Download the PHP package kozz/collection without Composer
On this page you can find all versions of the php package kozz/collection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kozz/collection
More information about kozz/collection
Files in kozz/collection
Package collection
Short Description Powerful Data Storage based on SplDoublyLinkedList
License MIT
Homepage http://github.com/urakozz/php-collection
Informations about the package collection
PHP Collection
Data Structure based on SplDoublyLinkedList.
Numerical keys, consequentially increasing, no gaps possible. Quick sequential iterating.
Advantages:
- Using Lamda Modifiers (see
addModifier
method) - Regular array compatiable (
ArrayAccess
interface implemented)
Installation
Add the package to your composer.json
and run composer update
.
{
"require": {
"kozz/collection": "*"
}
}
Basic Usage
Initializing
Initializing from any Traversable or Iterator
-
You can initiate collection as SplDoublyLinkedList-based structure with
Collection::from($traversable)
- You also able to use your
Iterator
asCollection
's data container withnew Collection($iterator)
. Your iterator will converts to SplDoublyLinkedList once you try use any method fromArrayAccess
orCountable
interfaces implemented inCollection
. This is good solution if your iterator is cursor in big DB Data Set and you need just add some modifiers withaddModifier
Modifiers
Sometimes you should modify your data in collection
With Collection
Modifiers are quite helpful to process DB Data Sets.
And with this Collection
you are able simply add modifier in just one line:
So now Modifiers are stored in Collection
and you have two ways to apply it:
-
use
getFilterIterator()
method to get an Iterator with all applied modifiers: - Call
->toArray()
that callsgetFilterIterator()
:
Without Collection
You actually can modify your data with plain SPL:
ArrayAccess
Adding element
Replacing element
Check offset
Retrieve element
Remove element