viloveul / event
Event Dispatcher of Viloveul
v1.1.0
2019-06-19 03:06 UTC
Requires
- php: ~7.0
- ext-spl: *
- fig/event-dispatcher-util: ^1.1
- psr/event-dispatcher: ^1.0
Requires (Dev)
- codeception/codeception: ^2.5
README
Installation
make sure your php version > 7.0
composer require viloveul/event
How
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());