1. Go to this page and download the library: Download pollen-solutions/event 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/ */
pollen-solutions / event example snippets
use Pollen\Event\EventDispatcher;
// Create Dispatcher
$dispatcher = new EventDispatcher();
// Subscribe events
$dispatcher->on('event.demo', function () {
var_dump('one');
});
$dispatcher->on('event.demo', function () {
var_dump('two');
});
// Dispatch events
$dispatcher->trigger('event.demo');
// Output
// >> (string) 'one'
// >> (string) 'two'
use Pollen\Event\EventDispatcher;
// Create Dispatcher
$dispatcher = new EventDispatcher();
// Subscribe events
$dispatcher->on('event.demo', function () {
var_dump('one');
}, 10);
$dispatcher->on('event.demo', function () {
var_dump('two');
}, 20);
// Dispatch events
$dispatcher->trigger('event.demo');
// Output
// >> (string) 'two'
// >> (string) 'one'
use Pollen\Event\EventDispatcher;
use Pollen\Event\StoppableEvent;
// Create Dispatcher
$dispatcher = new EventDispatcher();
// Subscribe events
$dispatcher->on('event.demo', function (StoppableEvent $e) {
$e->stopPropagation();
var_dump('one');
});
$dispatcher->on('event.demo', function () {
var_dump('two');
});
// Dispatch events
$dispatcher->trigger('event.demo');
// Output
// >> (string) 'one'