make sure your php version > 7.0
composer require viloveul/event
require __DIR__ . '/vendor/autoload.php';
class MyEvent
{
/**
* @var string
*/
public $name = 'foo';
}
class MyListener
{
/**
* @param MyEvent $event
*/
public function __invoke(MyEvent $event)
{
if ($event->name === 'foo') {
throw new Exception("foo");
} else {
throw new Exception("bar");
}
}
}
$provider = new Viloveul\Event\Provider();
$provider->addListener(new MyListener());
$dispatcher = new Viloveul\Event\Dispatcher($provider);
$dispatcher->dispatch(new MyEvent());