Created
June 5, 2014 10:47
-
-
Save yupe/8ec8e205ce7b6ce57600 to your computer and use it in GitHub Desktop.
EventDispatcher wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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