Download the PHP package echo-fusion/eventmanager without Composer
On this page you can find all versions of the php package echo-fusion/eventmanager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download echo-fusion/eventmanager
More information about echo-fusion/eventmanager
Files in echo-fusion/eventmanager
Package eventmanager
Short Description EventManager is a flexible and lightweight event handling system for PHP, allowing you to attach and trigger events with priorities and listeners.
License MIT
Homepage https://github.com/echo-fusion/eventmanager
Informations about the package eventmanager
EventManager
EventManager is a flexible and lightweight event handling system for PHP, allowing you to attach and trigger events with priorities and listeners.
Part of EchoFusion, a modular PHP framework built from small packages.
Installation
Requirements
- PHP 8.1, 8.2 or 8.3
Usage
Here’s how to use the EventManager to attach listeners and trigger an event:
Output:
PSR-14
EventManager is a PSR-14 event dispatcher and listener provider, so it can be used wherever a Psr\EventDispatcher\EventDispatcherInterface is expected, and replaced by any other PSR-14 dispatcher (such as Symfony's) without changing the code that dispatches.
A listener key is either an event name (for EventInterface events such as BaseEvent('user.register')) or the class or interface name of event objects; the listeners of every key that matches an event run together, highest priority first. An event that implements Psr\EventDispatcher\StoppableEventInterface (every EventInterface does) can stop propagation.
trigger($event) still works as a deprecated alias of dispatch($event).
Priorities, detaching and inspecting
- Listeners are sorted once per change, when the event is next triggered, not on every
attach(). - Attaching the same callable twice to an event throws
DuplicateListenerException. trigger()checksisPropagationStopped()before each listener, so a listener that calls$event->stopPropagation()skips the rest, and an event that is already stopped calls none.- A listener may detach itself (or another) while the event is being triggered.
Testing
Credits
License
The MIT License (MIT). Please see LICENSE for more information.
All versions of eventmanager with dependencies
echo-fusion/contracts Version ^2.0
psr/event-dispatcher Version ^1.0