PHP code example of piko / event-dispatcher

1. Go to this page and download the library: Download piko/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/ */

    

piko / event-dispatcher example snippets




use Piko\Event;
use Piko\ListenerProvider;
use Piko\EventDispatcher;

class MyEvent extends \Piko\Event
{
    public $value;
}

$provider = new ListenerProvider();
$dispatcher = new EventDispatcher($provider);
$event = new MyEvent();

$provider->addListenerForEvent(MyEvent::class, function(MyEvent $event) {
    $event->value .= 'World !';
});

$provider->addListenerForEvent(MyEvent::class, function(MyEvent $event) {
    $event->value .= 'Hello ';
}, 10); // Set the priority to 10

$dispatcher->dispatch($event);

echo $event->value; // Hello World!