open-engine / event-dispatcher
Event Dispatcher
0.1.0
2019-01-12 22:22 UTC
Requires
- php: ~7.2
- psr/event-dispatcher: ~0.7.0
Requires (Dev)
- open-engine/run-tests: ~0.1.1
This package is auto-updated.
Last update: 2024-11-14 00:04:33 UTC
README
Event dispatcher
Event
Event can be any class
Dispatch some event
$dispatcher = new EventDispatcher($listenerProvier); $event = $dispatcher->dispatch(new FooEvent());
Add listener to some event
$config = new ListenerProviderConfig(); $config->addListener(FooEvent::class, function (FooEvent $event) { // do somthing return $event; }, 20); $config->addListener(FooEvent::class, '\Acme\listeners\AnotherListener::methodName'); // add another listeners $listenerProvider = new ListenerProvider($config);
Add listener method parameters:
- $eventClass
string
- Event name. It always equals to event class name - $listener
callable
- Listener is any callabe wich have only one paramater $event. Listener must return same $event - $priority
int
- Optiona. Default is 1000. Zero is highest priority