Download the PHP package cunningsoft/generic-list without Composer
On this page you can find all versions of the php package cunningsoft/generic-list. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cunningsoft/generic-list
More information about cunningsoft/generic-list
Files in cunningsoft/generic-list
Package generic-list
Short Description This library provides the tools needed to create custom iterables without the need to repeat all the boilerplate code.
License MIT
Informations about the package generic-list
Generic List
This library provides the tools needed to create custom iterables without the need to repeat all the boilerplate code.
Installation
Install the library via composer:
Usage
Unsorted Lists
Create a custom list class (for example for Users):
Add common functionality by passing the method call down to the generic list:
Add functionality to customize the list to the specific needs:
Now you can use it like this:
Sorted Lists
Sorted lists work the same way as unsorted lists, but they use the SortedListConstructor
trait instead and because of that you have to provide a sorting function.
Now you can use this class in the same way as described above for the unsorted list, but by passing this type of object around you can be sure that it is always in the intended ordered state.
FAQ
Q: Why not simply use arrays?
A: You get type safety and can assign custom behaviour to each list.
Q: Why not simply extend the GenericList
, UnsortedGenericList
or SortedGenericList
?
A: This would create a huge inheritance tree, without any real benefit. This way for every list the exposed behaviour is exactly what it needed for every use case.
Contact
GitHub: https://github.com/dmecke
Twitter: @danielmecke