From c003b58ebf1a760dc53c4c8cdd86f70257a29440 Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Mon, 25 Aug 2014 20:31:35 +0200 Subject: [PATCH] make the ManagerRegistry service id configurable --- DependencyInjection/Configuration.php | 1 + .../DoctrinePHPCRExtension.php | 8 +++++-- Tests/Resources/Fixtures/config/single.php | 1 + Tests/Resources/Fixtures/config/single.xml | 1 + Tests/Resources/Fixtures/config/single.yml | 1 + .../DependencyInjection/ConfigurationTest.php | 3 +++ .../DoctrinePHPCRExtensionTest.php | 22 +++++++++++++++++++ 7 files changed, 35 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 820da5d6..480b47e8 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -41,6 +41,7 @@ public function getConfigTreeBuilder() ->scalarNode('jackrabbit_jar')->end() ->scalarNode('workspace_dir')->end() ->scalarNode('dump_max_line_length')->defaultValue(120)->end() + ->scalarNode('manager_registry_service_id')->defaultNull()->end() ->end() ; diff --git a/DependencyInjection/DoctrinePHPCRExtension.php b/DependencyInjection/DoctrinePHPCRExtension.php index 455eed44..a936cc53 100644 --- a/DependencyInjection/DoctrinePHPCRExtension.php +++ b/DependencyInjection/DoctrinePHPCRExtension.php @@ -61,6 +61,12 @@ public function load(array $configs, ContainerBuilder $container) $config = $processor->processConfiguration($configuration, $configs); $this->loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $this->loader->load('phpcr.xml'); + + if (!empty($config['manager_registry_service_id'])) { + $container->setAlias('doctrine_phpcr', new Alias($config['manager_registry_service_id'])); + } + $parameters = array( 'workspace_dir', 'jackrabbit_jar', @@ -104,8 +110,6 @@ private function loadTypeGuess($config, ContainerBuilder $container) private function sessionLoad($config, ContainerBuilder $container) { - $this->loader->load('phpcr.xml'); - $sessions = $loaded = array(); foreach ($config['sessions'] as $name => $session) { if (empty($config['default_session'])) { diff --git a/Tests/Resources/Fixtures/config/single.php b/Tests/Resources/Fixtures/config/single.php index 06f9c303..d5a2f14b 100644 --- a/Tests/Resources/Fixtures/config/single.php +++ b/Tests/Resources/Fixtures/config/single.php @@ -60,4 +60,5 @@ ), 'jackrabbit_jar' => '/path/to/jackrabbit.jar', 'dump_max_line_length' => 20, + 'manager_registry_service_id' => 'my_phpcr_registry', )); diff --git a/Tests/Resources/Fixtures/config/single.xml b/Tests/Resources/Fixtures/config/single.xml index 7aa91ce1..04f1c64f 100644 --- a/Tests/Resources/Fixtures/config/single.xml +++ b/Tests/Resources/Fixtures/config/single.xml @@ -4,6 +4,7 @@ '/path/to/jackrabbit.jar', 'dump_max_line_length' => 20, + 'manager_registry_service_id' => 'my_phpcr_registry', ); $multipleConfiguration = array( 'session' => array( @@ -194,6 +195,7 @@ public function configurations() ), ), 'dump_max_line_length' => 120, + 'manager_registry_service_id' => null, ); $bc = array( 'session' => array( @@ -220,6 +222,7 @@ public function configurations() ), ), 'dump_max_line_length' => 120, + 'manager_registry_service_id' => null, ); return array( diff --git a/Tests/Unit/DependencyInjection/DoctrinePHPCRExtensionTest.php b/Tests/Unit/DependencyInjection/DoctrinePHPCRExtensionTest.php index b1573c73..ecdec606 100644 --- a/Tests/Unit/DependencyInjection/DoctrinePHPCRExtensionTest.php +++ b/Tests/Unit/DependencyInjection/DoctrinePHPCRExtensionTest.php @@ -55,6 +55,28 @@ public function testJackrabbitSession() $this->assertEquals('doctrine_phpcr.jackalope.repository.factory.jackrabbit', $repositoryFactory->getParent()); } + public function testCustomManagerRegistryService() + { + $this->container->setDefinition('my_phpcr_registry', new Definition('\stdClass')); + + $this->load(array( + 'session' => array( + 'backend' => array( + 'url' => 'http://localhost', + ), + 'workspace' => 'default', + 'username' => 'admin', + 'password' => 'admin', + ), + 'manager_registry_service_id' => 'my_phpcr_registry', + )); + + /** @var $repositoryFactory DefinitionDecorator */ + $managerRegistry = $this->container->getAlias('doctrine_phpcr'); + $this->assertInstanceOf('\Symfony\Component\DependencyInjection\Alias', $managerRegistry); + $this->assertEquals('my_phpcr_registry', $managerRegistry); + } + public function testJackrabbitSessions() { $this->load(array(