yigitcukuren/event-dispatcher

There is no license information available for the latest version (v1.0.1) of this package.

Simple PSR-14 Event Dispatcher

v1.0.1 2020-09-30 18:37 UTC

This package is not auto-updated.

Last update: 2022-11-25 03:26:13 UTC


README

Simple PSR-14 Event Dispatcher

Example Usage

use App\Events\AppOpened;
use App\Listeners\First;
use App\Listeners\Second;
use YigitCukuren\Events\EventDispatcher;
use YigitCukuren\Events\ListenerProvider\PriorityListenerProvider;

$dispatcher = new EventDispatcher(new PriorityListenerProvider());
$dispatcher->subscribe(AppOpened::class, new First(), 0);
$dispatcher->subscribe(AppOpened::class, new Second(), 1);
$dispatcher->subscribe(AppOpened::class, function (AppOpened $event) {
  echo '<pre>';
  var_dump($event);
}, 2);

$dispatcher->dispatch(new AppOpened('app'));