1. Go to this page and download the library: Download azurre/php-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/ */
azurre / php-event-dispatcher example snippets
$loader = re\EventDispatcher\Dispatcher;
use Azurre\EventDispatcher\Event;
$dispatcher = new Dispatcher();
$dispatcher->attachListener(new Logger());
// ...
// Do something
// ...
$event = new Event('my.event', new MyObject());
$dispatcher->dispatch($event);
$someData = $event->getData('some_data');
class Logger implements \Azurre\EventDispatcher\ListenerInterface
{
public function getKey(): string
{
return 'my.event.logger';
}
public function getListenedEvents(): array
{
return ['my.event', 'my.another.event'];
}
public function execute(\Azurre\EventDispatcher\EventInterface $event): void
{
switch ($event->getKey()) {
case 'my.event':
// Modify data
$data = $event->getData();
$data->setIsLogged(true);
$event->setData('some_data', [1,2,3]);
break;
case 'my.another.event':
// Do another things
break;
}
}
}
curl -s https://getcomposer.org/installer | php
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.