Skip to content

Commit

Permalink
make the ManagerRegistry service id configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Aug 31, 2014
1 parent 180dee2 commit c003b58
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
;

Expand Down
8 changes: 6 additions & 2 deletions DependencyInjection/DoctrinePHPCRExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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'])) {
Expand Down
1 change: 1 addition & 0 deletions Tests/Resources/Fixtures/config/single.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@
),
'jackrabbit_jar' => '/path/to/jackrabbit.jar',
'dump_max_line_length' => 20,
'manager_registry_service_id' => 'my_phpcr_registry',
));
1 change: 1 addition & 0 deletions Tests/Resources/Fixtures/config/single.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<config xmlns="http://doctrine-project.org/schema/symfony-dic/odm/phpcr"
jackrabbit_jar="/path/to/jackrabbit.jar"
dump_max_line_length="20"
manager_registry_service_id="my_phpcr_registry"
>

<session
Expand Down
1 change: 1 addition & 0 deletions Tests/Resources/Fixtures/config/single.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ doctrine_phpcr:

jackrabbit_jar: /path/to/jackrabbit.jar
dump_max_line_length: 20
manager_registry_service_id: my_phpcr_registry
3 changes: 3 additions & 0 deletions Tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public function configurations()
),
'jackrabbit_jar' => '/path/to/jackrabbit.jar',
'dump_max_line_length' => 20,
'manager_registry_service_id' => 'my_phpcr_registry',
);
$multipleConfiguration = array(
'session' => array(
Expand Down Expand Up @@ -194,6 +195,7 @@ public function configurations()
),
),
'dump_max_line_length' => 120,
'manager_registry_service_id' => null,
);
$bc = array(
'session' => array(
Expand All @@ -220,6 +222,7 @@ public function configurations()
),
),
'dump_max_line_length' => 120,
'manager_registry_service_id' => null,
);

return array(
Expand Down
22 changes: 22 additions & 0 deletions Tests/Unit/DependencyInjection/DoctrinePHPCRExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c003b58

Please sign in to comment.