dev-master
9999999-devLibrary to provide collection structures, to use instead of arrays
MIT
The Requires
- php ^7.1
The Development Requires
by Jose Diaz
Library to provide collection structures, to use instead of arrays
PHP Arrays with additional functionality. Arrays on steroids., (*1)
There are two ways of using this library. To create Collections of objects or Collections of PHP scalar types., (*2)
To create you own Collection, the easiest way is to copy and adjust the sample CarCollection
, replacing Car
with
the class that you need., (*3)
More generically, these are the steps to create your own Collection:
- Extend the AbstractCollection
class
- Implement on the child these methods,
- getClass()
to provide information about the expected class or interface that all the objects on the collection
should be.
- offsetGet($offset)
to specify the return class.
- toArray()
to provide PHPDoc information about the elements of the array.
- first()
to specify the return class., (*4)
This library comes out of the box with the following Collections, ready to use:
- StringCollection
- StringOrNullCollection
- IntegerCollection
- IntegerOrNullCollection
, (*5)
These classes include additional expected functionality that you would expect from the data type, e.g. implode()
,
sum()
, ..., (*6)
If they do not suit your needs, you can extend any of them or the AbstractScalarTypeCollection
to implement your own., (*7)
Library to provide collection structures, to use instead of arrays
MIT