1. Go to this page and download the library: Download circli/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.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
circli / event-dispatcher example snippets
useCircli\EventDispatcher\EventDispatcher;
useCircli\EventDispatcher\ListenerProvider\DefaultProvider;
$provider = new DefaultProvider();
$dispatcher = new EventDispatcher($provider);
$provider->listen(Event::class, function(Event $e){
// do stuff
});
$dispatcher->dispatch(new Event());
useCircli\EventDispatcher\ListenerProvider\DefaultProvider;
$provider = new DefaultProvider();
$provider->listen(Event::class, $listener);
useCircli\EventDispatcher\ListenerProvider\PriorityProvider;
$provider = new PriorityProvider();
//Add listener with lower than default priority
$provider->listen(Event::class, $listener, 900);
//Add listener with higher than default priority
$provider->listen(Event::class, $listener, 1100);
//Add listener with normal priority
$provider->listen(Event::class, $listener);
useCircli\EventDispatcher\ListenerProvider\ContainerListenerProvider;
$container = new SomePsr11Container();
$provider = new ContainerListenerProvider($container);
$provider->addService(Event::class, EventListener::class);
useCircli\EventDispatcher\ListenerProvider\PriorityAggregateProvider;
useCircli\EventDispatcher\ListenerProvider\DefaultProvider;
$aggregateProvider = new PriorityAggregateProvider();
$aggregateProvider->addProvider(new DefaultProvider());
// Add with higher than default priority
$aggregateProvider->addProviderWithPriority(new DefaultProvider(), 1500);
// Add with lower than default priority
$aggregateProvider->addProviderWithPriority(new DefaultProvider(), 500);