From eaccee50dc85f33a016494c8764a8ccd8fecbc53 Mon Sep 17 00:00:00 2001 From: Bulat Shakirzyanov Date: Mon, 13 Jun 2011 17:51:42 -0400 Subject: [PATCH] Add orm2odm references support Conflicts: DependencyInjection/Configuration.php DependencyInjection/StofDoctrineExtensionsExtension.php Resources/config/listeners.xml --- DependencyInjection/Configuration.php | 6 ++++ .../StofDoctrineExtensionsExtension.php | 14 ++++++++++ Listener/ReferencesListener.php | 28 +++++++++++++++++++ Resources/config/listeners.xml | 5 ++++ 4 files changed, 53 insertions(+) create mode 100644 Listener/ReferencesListener.php diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 30e67590..47eaa4c1 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -49,6 +49,7 @@ private function getVendorNode($name) ->prototype('array') ->performNoDeepMerging() ->children() + ->scalarNode('translatable')->defaultFalse()->end() ->scalarNode('timestampable')->defaultFalse()->end() ->scalarNode('blameable')->defaultFalse()->end() @@ -59,6 +60,7 @@ private function getVendorNode($name) ->scalarNode('softdeleteable')->defaultFalse()->end() ->scalarNode('uploadable')->defaultFalse()->end() ->scalarNode('reference_integrity')->defaultFalse()->end() + ->scalarNode('references')->cannotBeEmpty()->end() ->end() ->end() ; @@ -114,6 +116,10 @@ private function getClassNode() ->cannotBeEmpty() ->defaultValue('Gedmo\\ReferenceIntegrity\\ReferenceIntegrityListener') ->end() + ->scalarNode('references') + ->cannotBeEmpty() + ->defaultValue('Stof\\DoctrineExtensionsBundle\\Listener\\ReferencesListener') + ->end() ->end() ; diff --git a/DependencyInjection/StofDoctrineExtensionsExtension.php b/DependencyInjection/StofDoctrineExtensionsExtension.php index f42b3374..99bf633b 100644 --- a/DependencyInjection/StofDoctrineExtensionsExtension.php +++ b/DependencyInjection/StofDoctrineExtensionsExtension.php @@ -37,6 +37,8 @@ public function load(array $configs, ContainerBuilder $container) $useLoggable = false; $useBlameable = false; + $managers = array(); + foreach ($config['orm'] as $name => $listeners) { foreach ($listeners as $ext => $enabled) { $listener = sprintf('stof_doctrine_extensions.listener.%s', $ext); @@ -53,6 +55,10 @@ public function load(array $configs, ContainerBuilder $container) } $definition = $container->getDefinition($listener); $definition->addTag('doctrine.event_subscriber', $attributes); + + if ('references' === $ext) { + $managers[$enabled] = sprintf('doctrine.orm.%s_entity_manager', $name); + } } } @@ -75,6 +81,10 @@ public function load(array $configs, ContainerBuilder $container) } $definition = $container->getDefinition($listener); $definition->addTag('doctrine_mongodb.odm.event_subscriber', $attributes); + + if ('references' === $ext) { + $managers[$enabled] = sprintf('doctrine_mongodb.odm.%s_document_manager', $name); + } } } $this->documentManagers[$name] = $listeners; @@ -117,6 +127,10 @@ public function load(array $configs, ContainerBuilder $container) ); } + $container + ->getDefinition('stof_doctrine_extensions.listener.references') + ->setArguments(array(new Reference('service_container'), $managers)); + foreach ($config['class'] as $listener => $class) { $container->setParameter(sprintf('stof_doctrine_extensions.listener.%s.class', $listener), $class); } diff --git a/Listener/ReferencesListener.php b/Listener/ReferencesListener.php new file mode 100644 index 00000000..1cb671c4 --- /dev/null +++ b/Listener/ReferencesListener.php @@ -0,0 +1,28 @@ + + */ +class ReferencesListener extends BaseReferencesListener +{ + private $container; + + public function __construct(ContainerInterface $container, array $managers = array()) + { + $this->container = $container; + parent::__construct($managers); + } + + public function getManager($type) + { + return $this->container->get(parent::getManager($type)); + } +} diff --git a/Resources/config/listeners.xml b/Resources/config/listeners.xml index f704a52b..e360e95f 100644 --- a/Resources/config/listeners.xml +++ b/Resources/config/listeners.xml @@ -14,6 +14,11 @@ + + + + +