open-engine/event-dispatcher

0.1.0 2019-01-12 22:22 UTC

This package is auto-updated.

Last update: 2024-11-14 00:04:33 UTC


README

Latest Stable Version Code Quality Code intelligence License

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