Created
August 13, 2013 21:06
-
-
Save SofHad/6225719 to your computer and use it in GitHub Desktop.
This file contains 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
{ | |
"require": { | |
"symfony/event-dispatcher": "2.1.0-stable" | |
} | |
} |
This file contains 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 | |
require_once 'vendor/autoload.php'; | |
use Symfony\Component\EventDispatcher\EventDispatcher; | |
use Symfony\Component\EventDispatcher\Event; | |
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
class CallbackAggregateSubscriber implements EventSubscriberInterface { | |
public static function getSubscribedEvents(){ | |
return array( | |
'setup' => 'onSetup', | |
'teardown' => 'onTearDown', | |
); | |
} | |
public function onSetUp(Event $event){ | |
echo 'CallbackAggregateSubscriber:' . $event->getName() . "\n"; | |
} | |
public function onTearDown(Event $event){ | |
echo 'CallbackAggregateSubscriber:' . $event->getName() . "\n"; | |
} | |
} | |
$eventManager = new EventDispatcher(); | |
//Subscriber | |
$eventManager->addSubscriber( new CallbackAggregateSubscriber() ); | |
//Closure | |
$eventManager->addListener('setup', function(Event $event){ | |
echo $event->getName() . "\n"; | |
}); | |
//Notify event | |
$eventManager->dispatch('setup'); | |
$eventManager->dispatch('teardown'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment