PHP code example of yigitcukuren / event-dispatcher
1. Go to this page and download the library: Download yigitcukuren/event-dispatcher library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yigitcukuren / event-dispatcher example snippets
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'));