Download the PHP package raphhh/trex-collection without Composer
On this page you can find all versions of the php package raphhh/trex-collection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download raphhh/trex-collection
More information about raphhh/trex-collection
Files in raphhh/trex-collection
Package trex-collection
Short Description Helpers to manipulate collections
License MIT
Informations about the package trex-collection
TRex Collection
Install
$ composer require raphhh/trex-collection
Usages
Collection
Collection
is just an ArrayObject
implementing some additional methods.
Because Collection
is just a facade, you can keep coding with ArrayObject
(or any object castable into an array) and implement some TRex traits by yourself:
Filter
Provide methods to filter a collection.
Filter values with a callback: filter
Apply a callback to the values: each
Extract a part of the list: extract
Comparator
Merge any collections: merge, mergeA
Find the difference between any collections: diff, diffA, diffK
Find the intersection between any collections: intersect, intersectA, intersectK
Sorter
Reindex collection: reindex
Sort collection: sort
Group by specific values: groupBy
Values
Retrieve first value: first
Retrieve last value: last
Check is has value: has
Keys
Search keys: search
Extract keys: keys
Sorter
Sort a collection by a property or a method result.
You need to extends the class TRex\Collection\AbstractSorter
.
In the method invoke
, you have to return the value to sort for each object the collection content.
Note that the TRex sorter implements duck typing. You should create a sorter by key to access to the data, and not by type of collection content. For example, if you want to sort a collection of objects by them property '$foo', you should call your sorter 'FooSorter', anyway the objects the collection content.
Filter
You need to extends the class TRex\Collection\AbstractFilter
.
In the method invoke
, you have to return the value to compare for each object the collection content.
Note that the TRex filter implements duck typing. You should create a filter by key to access to the data, and not by type of collection content. For example, if you want to sort a collection of objects by them property '$foo', you should call your sorter 'FooSorter', anyway the objects the collection content.