PHP code example of codin / events
1. Go to this page and download the library: Download codin/events 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/ */
codin / events example snippets
class MyListener implements \Psr\EventDispatcher\ListenerProviderInterface
{
public function getListenersForEvent(object $event) : iterable
{
yield static function (MyEvent $event) {
echo "$event->message\n";
};
}
}
class MyEvent {
public string $message = 'Hello World';
}
$dispatcher = new Codin\Events\EventDispatcher();
$dispatcher->registerListener(new MyListener());
$dispatcher->dispatch(new MyEvent());