sharkzt / collections
Generic-like collections for php, inspired by OOP languages structures
0.1.0
2017-10-15 14:38 UTC
Requires
- php: >=7.1.0
Requires (Dev)
- mockery/mockery: dev-master
- phpunit/phpunit: >=6.4
This package is not auto-updated.
Last update: 2025-02-02 06:37:20 UTC
README
Collections for php, inspired by OOP generic languages structures
Installation
The recommended way to install bundle is through Composer:
$ composer require sharkzt/collections
Usage Examples
ArrayList
//rough example of ArrayListcreation, usually goes in constructor; see examples classes $user = new User(); $user->articles = new ArrayList(Article::class);
ArrayList will accept only Article instances as arguments.
//addAll argument can be any iterable form, like ArrayList $user->articles->addAll([ (new Article()) ->setTitle('foo') ->setContent('bar'), (new Article()) ->setTitle('baz') ->setContent('qux'), ]); $singleArticle = (new Article()) ->setTitle('foo') ->setContent('bar'); $user->articles->add($singleArticle);
Can add iterable articles, or single invoking add method.
if ($user->articles->contains($singleArticle)) { $user->articles->remove($singleArticle); } foreach ($user->articles as $article) { if ($article->getContent() === 'qux') { $article->setTitle('foo'); break; } }
Possible usage examples.
License
Collections classes are released under the MIT License. See the bundled LICENSE file for details.