Download the PHP package phly/phly-event-emitter without Composer
On this page you can find all versions of the php package phly/phly-event-emitter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package phly-event-emitter
phly-event-emitter
Experimental!
This library is experimental, tracking different iterations and experiments being proposed for PSR-14. It is highly unstable in terms of API; use at your own risk.
This library provides an implementation of the following proposed PSR-14 interfaces:
-
ListenerProvider
implementsListenerProviderInterface
, and allows you to attach listeners to any message type. It then acts as a generator, looping through each listener and testing if it handles the message type. -
PrioritizedListenerProvider
also implementsListenerProviderInterface
, and allows you to attach listeners to any message type, with an integer priority. When listeners are retrieved, it loops through all attached listeners, and injects those capable of listening to the emitted message to a priority queue, which it then returns. -
MessageNotifier
implementsMessageNotifierInterface
, and accepts aListenerProviderInterface
to its constructor. It then loops through and notifies listeners returned for the message. If any listeners throw exceptions, it catches them, and, when all listeners have been notified, throws aPhly\EventEmitter\Exception\ExceptionAggregate
that aggregates all of them; call thegetListenerExceptions()
method of that class to iterate through them. TaskProcessor
implementsTaskProcessorInterface
, and accepts aListenerProviderInterface
to its constructor. It then loops through and processes listeners returned for the task, halting early if the task is stoppable and indicates propagation has been stopped. Exceptions thrown by listeners are not caught.
It DOES NOT provide implementations for the following interfaces:
EventInterface
(consumers will create these)MessageInterface
(consumers will create these)TaskInterface
(consumers will create these)StoppableTaskInterface
(consumers will create these)
Installation
You will first need to add a repository entry to your composer.json
:
Then, run the following to install this library:
Documentation
Basic usage
The following demonstrates using the ListenerProvider
to attach a listener.
The provider is then used to seed either a MessageNotifier
or TaskProcessor
.
Prioritized listeners
The following example uses a PrioritizedListenerProvider
to provide three
different listeners, each with a different priority. Priorities are integers;
higher priorities execute first, while lower priorities (including negative
priorities) execute last.
In the above, the output will become:
Support
All versions of phly-event-emitter with dependencies
fig/event-dispatcher-util Version ^0.6.1
psr/event-dispatcher-message Version ^0.6
psr/event-dispatcher-task Version ^0.6
zendframework/zend-stdlib Version ^3.2