Skip to content

Instantly share code, notes, and snippets.

@h2rd
Created March 15, 2013 10:35
Show Gist options
  • Select an option

  • Save h2rd/5168901 to your computer and use it in GitHub Desktop.

Select an option

Save h2rd/5168901 to your computer and use it in GitHub Desktop.
Symfony Event Dispatcher
require_once __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\Event;
$dispatcher = new EventDispatcher();
$dispatcher->addListener('event_name', function(Event $event) {
echo $event->getName(), ' Done', "\n";
});
$dispatcher->dispatch('event_name');
$dispatcher->dispatch('event_name');
$dispatcher->addListener('event_name_2', function(Event $event) {
echo $event->getName(), ' Done', "\n";
});
$dispatcher->dispatch('event_name_2');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment