From b932441ac9270a664e20a3ca8cf4888234ea2b05 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Sat, 6 Nov 2010 11:17:54 -0700 Subject: [PATCH] [DoctrineMongoDBBundle] added ability to register global listeners and subscribers via the DIC --- .../DoctrineMongoDBExtension.php | 6 ++++++ .../DoctrineMongoDBBundle/Event/EventManager.php | 14 ++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php index 14202600cc..6ad465bc66 100755 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php @@ -136,10 +136,16 @@ class DoctrineMongoDBExtension extends Extension $eventManagerId = sprintf('doctrine.odm.mongodb.%s_event_manager', $eventManagerName); if (!$container->hasDefinition($eventManagerId)) { $eventManagerDef = new Definition('%doctrine.odm.mongodb.event_manager_class%'); + $eventManagerDef->addMethodCall('loadTaggedEventListeners', array( + new Reference('service_container'), + )); $eventManagerDef->addMethodCall('loadTaggedEventListeners', array( new Reference('service_container'), sprintf('doctrine.odm.mongodb.%s_event_listener', $eventManagerName), )); + $eventManagerDef->addMethodCall('loadTaggedEventSubscribers', array( + new Reference('service_container'), + )); $eventManagerDef->addMethodCall('loadTaggedEventSubscribers', array( new Reference('service_container'), sprintf('doctrine.odm.mongodb.%s_event_subscriber', $eventManagerName), diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Event/EventManager.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Event/EventManager.php index 68443ab556..04ad900fcf 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Event/EventManager.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Event/EventManager.php @@ -10,10 +10,15 @@ class EventManager extends BaseEventManager /** * Loads event listeners from the service container. * + * + * + * + * + * * @param TaggedContainerInterface $container The service container * @param string $tagName The name of the tag to load */ - public function loadTaggedEventListeners(TaggedContainerInterface $container, $tagName) + public function loadTaggedEventListeners(TaggedContainerInterface $container, $tagName = 'doctrine.odm.mongodb.event_listener') { foreach ($container->findTaggedServiceIds($tagName) as $id => $instances) { $events = array(); @@ -32,13 +37,14 @@ class EventManager extends BaseEventManager /** * Loads event subscribers from the service container. * - * A service can be marked as an event subscriber using the - * "doctrine.odm.mongodb.event_subscriber" tag: + * + * + * * * @param TaggedContainerInterface $container The service container * @param string $tagName The name of the tag to load */ - public function loadTaggedEventSubscribers(TaggedContainerInterface $container, $tagName) + public function loadTaggedEventSubscribers(TaggedContainerInterface $container, $tagName = 'doctrine.odm.mongodb.event_subscriber') { foreach ($container->findTaggedServiceIds($tagName) as $id => $instances) { $this->addEventSubscriber($container->get($id));