Download the PHP package flying/handlers-list without Composer
On this page you can find all versions of the php package flying/handlers-list. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download flying/handlers-list
More information about flying/handlers-list
Files in flying/handlers-list
Package handlers-list
Short Description Implementation of generic list of arbitrary handlers
License MIT
Informations about the package handlers-list
Generic list of arbitrary handlers
This very simple library provides implementation of generic list of arbitrary handlers.
Its primary goal is to simplify process of organizing multiple related objects into iterable list of handlers with:
- Ensuring type correctness by providing class constraint, handlers need to implement / extend
- Support for defining handlers priority
Requirements
No dependencies are required, just PHP 7.4 or 8.x.
Example
In a case if some handler implements PrioritizedHandlerInterface
- its priority is considered:
Example above will output B A
because B
have higher priority then A
despite the fact that it was put later in the list of handlers.
Methods
It is, of course, possible to modify list of handlers:
set()
- set new list of handlersadd()
- add a new handler to the listremove()
- remove given handler from the listclear()
- remove all handlers from the list
There is also several methods for inspecting list of handlers:
isEmpty()
- check if handlers list is emptycount()
- get number of handlers in the listaccepts()
- check if list accepts a given object or objects of given casscontains()
- check if given handler is available in the listfilter()
- filter handlers list using provided test callable and return array of matching handlersfind()
- searches for a handler using provided callablegetIterator()
- get handlers from the list as iteratortoArray()
- get handlers from the list as array
And remaining methods:
getConstraint()
- get class constraint that is applied to handlers in this list
Immutable handlers list
Besides default, mutable implementation of handlers list there is also immutable version: ImmutableHandlersList
. Its functionality is completely same in except of list modification methods that returns new copy of the list instead of modifying original one.
License
MIT License