PHP code example of sy / event
1. Go to this page and download the library: Download sy/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/ */
sy / event example snippets
use Sy\Event\EventDispatcher;
use Sy\Event\Event;
$eventDispatcher = new EventDispatcher();
// Add an event listener on an event named "myEvent"
$eventDispatcher->addListener('myEvent', function (object $event) {
echo 'An event occurs: ' . $event->getName();
});
// Dispatch an event called "myEvent"
$eventDispatcher->dispatch(new Event('myEvent'));