Collections
Collections for php, inspired by OOP generic languages structures, (*1)
, (*2)
Installation
The recommended way to install bundle is through
Composer:, (*3)
$ composer require sharkzt/collections
Usage Examples
ArrayList
``` php
//rough example of ArrayListcreation, usually goes in constructor; see examples classes
$user = new User();
$user->articles = new ArrayList(Article::class);, (*4)
ArrayList will accept only Article instances as arguments.
``` php
//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., (*5)
``` php
if ($user->articles->contains($singleArticle)) {
$user->articles->remove($singleArticle);
}, (*6)
foreach ($user->articles as $article) {
if ($article->getContent() === 'qux') {
$article->setTitle('foo');
break;
}
}
```, (*7)
Possible usage examples., (*8)
License
Collections classes are released under the MIT License. See the bundled LICENSE file for
details., (*9)