Wallogit.com
2017 © Pedro Peláez
Simply and light event dispatcher. Let's build your own system using abdulklarapl's components!
git clone git@github.com:abdulklarapl/EventDispatcher.git
"adulklarapl/eventdispatcher": "dev-master" to your composer.json / require sectionAbdulklarapl's EventDispatcher is a simply and light event dispatcher. Let's build your own system using abdulklarapl's components!, (*2)
First, create your subscriber:, (*3)
<?php
namespace Acme\EventSubscriber;
use Abdulklarapl\Components\EventDispatcher\Subscriber\SubscriberInterface;
use Abdulklarapl\Components\EventDispatcher\Event\Event;
class SampleSubscriber implements SubscriberInterface
{
public function getSubscribedEvents()
{
return array(
"foo.bar" => 'fooAction'
);
}
/**
* method that it's called on 'event.foo'
*
* @param Event $event
*/
public function fooAction(Event $event)
{
// I just handled the event!
}
}
Then, create new instance of EventDispatcher:, (*4)
$subscriber = new SampleSubscriber();
$dispatcher = new Dispatcher();
$dispatcher->addSubscriber($subscriber);
$dispatcher->fire('foo.bar');
If you don't want to event was propagated after your subscribed calls, you can modify the event:, (*5)
public function fooAction(Event $event)
{
$event->stopPropagation();
}