03/05
2018
dev-master
9999999-dev
MIT
The Development Requires
by Michael Bardsley
Wallogit.com
2017 © Pedro Peláez
Events can either extend the AbstractEvent class or implement the EventInterface
Some simple examples, (*2)
class SampleEventOne extends AbstractEvent
{
protected $handle = 'sample-event-one';
public function handle(array $params = null) : bool
{
return true;
}
}
class SampleEventTwo extends AbstractEvent
{
protected $handle = 'sample-event-two';
public function handle(array $params = null) : bool
{
return true;
}
}
When you have created some events you can add them to the dispatcher. With this you can trigger events using the handle or using a wildcard to trigger multiple events., (*3)
$dispatcher = new Dispatcher;
$dispatcher->addEvent(new SampleEventOne);
$dispatcher->addEvent(new SampleEventTwo);
$dispatcher->addEvent(new SampleEventTwo, 'custom-handle-one');
$dispatcher->trigger('custom-handle-one'); //triggers one event
$dispatcher->trigger('sample-event*'); //triggers two events
MIT