Skip to content

Instantly share code, notes, and snippets.

@yupe
Created June 5, 2014 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yupe/8ec8e205ce7b6ce57600 to your computer and use it in GitHub Desktop.
Save yupe/8ec8e205ce7b6ce57600 to your computer and use it in GitHub Desktop.
EventDispatcher wrapper
<?php
namespace yupe\components;
use Symfony\Component\EventDispatcher\Event;
use Yii;
use CApplicationComponent;
use Symfony\Component\EventDispatcher\EventDispatcher;
class EventManager extends CApplicationComponent
{
/**
* @var Symfony\Component\EventDispatcher\EventDispatcher $dispatcher
*/
protected $dispatcher;
public $events = array();
public function init()
{
$this->dispatcher = new EventDispatcher();
foreach($this->events as $event => $listeners) {
foreach($listeners as $listener){
$this->dispatcher->addListener($event, $listener);
}
}
parent::init();
}
public function fire($eventName, Event $event)
{
$this->dispatcher->dispatch($eventName, $event);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment