Skip to content

Commit

Permalink
[DoctrineBundle] moved more DIC definition into orm.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed May 4, 2011
1 parent 6d33428 commit f7808de
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ protected function dbalLoad(array $config, ContainerBuilder $container)
$keys = array_keys($config['connections']);
$config['default_connection'] = reset($keys);
}
$this->defaultConnection = $config['default_connection'];

$container->setAlias('database_connection', sprintf('doctrine.dbal.%s_connection', $config['default_connection']));
$container->setAlias('doctrine.dbal.event_manager', new Alias(sprintf('doctrine.dbal.%s_connection.event_manager', $config['default_connection']), false));
$container->setAlias('database_connection', sprintf('doctrine.dbal.%s_connection', $this->defaultConnection));
$container->setAlias('doctrine.dbal.event_manager', new Alias(sprintf('doctrine.dbal.%s_connection.event_manager', $this->defaultConnection), false));

$container->getDefinition('doctrine.dbal.connection_factory')->replaceArgument(0, $config['types']);

Expand All @@ -75,7 +76,7 @@ protected function dbalLoad(array $config, ContainerBuilder $container)
$connections[$name] = sprintf('doctrine.dbal.%s_connection', $name);
}
$container->getDefinition('doctrine')->replaceArgument(1, $connections);
$container->getDefinition('doctrine')->replaceArgument(3, $config['default_connection']);
$container->getDefinition('doctrine')->replaceArgument(3, $this->defaultConnection);

foreach ($config['connections'] as $name => $connection) {
$this->loadDbalConnection($name, $connection, $container);
Expand Down Expand Up @@ -220,23 +221,21 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $
}
}

$entityManagerService = sprintf('doctrine.orm.%s_entity_manager', $entityManager['name']);
$connectionId = isset($entityManager['connection']) ? sprintf('doctrine.dbal.%s_connection', $entityManager['connection']) : 'database_connection';
$eventManagerID = isset($entityManager['connection']) ? sprintf('doctrine.dbal.%s_connection.event_manager', $entityManager['connection']) : 'doctrine.dbal.event_manager';

$ormEmArgs = array(
new Reference($connectionId),
new Reference(sprintf('doctrine.orm.%s_configuration', $entityManager['name']))
);
if (!isset($entityManager['connection'])) {
$entityManager['connection'] = $this->defaultConnection;
}

$ormEmDef = new Definition('%doctrine.orm.entity_manager.class%', $ormEmArgs);
$ormEmDef->setFactoryClass('%doctrine.orm.entity_manager.class%');
$ormEmDef->setFactoryMethod('create');
$container->setDefinition($entityManagerService, $ormEmDef);
$container
->setDefinition(sprintf('doctrine.orm.%s_entity_manager', $entityManager['name']), new DefinitionDecorator('doctrine.orm.entity_manager.abstract'))
->setArguments(array(
new Reference(sprintf('doctrine.dbal.%s_connection', $entityManager['connection'])),
new Reference(sprintf('doctrine.orm.%s_configuration', $entityManager['name']))
))
;

$container->setAlias(
sprintf('doctrine.orm.%s_entity_manager.event_manager', $entityManager['name']),
new Alias($eventManagerID, false)
new Alias(sprintf('doctrine.dbal.%s_connection.event_manager', $entityManager['connection']), false)
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bundle/DoctrineBundle/Resources/config/orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@
</service>

<service id="doctrine.orm.configuration" class="%doctrine.orm.configuration.class%" abstract="true" public="false" />

<service id="doctrine.orm.entity_manager.abstract" class="%doctrine.orm.entity_manager.class%" factory-class="%doctrine.orm.entity_manager.class%" factory-method="create" abstract="true" />
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function testDependencyInjectionConfigurationDefaults()

$arguments = $definition->getArguments();
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]);
$this->assertEquals('database_connection', (string) $arguments[0]);
$this->assertEquals('doctrine.dbal.default_connection', (string) $arguments[0]);
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]);
$this->assertEquals('doctrine.orm.default_configuration', (string) $arguments[1]);

Expand Down Expand Up @@ -195,7 +195,7 @@ public function testSingleEntityManagerConfiguration()
$this->assertEquals('create', $definition->getFactoryMethod());

$this->assertDICConstructorArguments($definition, array(
new Reference('database_connection'), new Reference('doctrine.orm.default_configuration')
new Reference('doctrine.dbal.default_connection'), new Reference('doctrine.orm.default_configuration')
));
}

Expand Down Expand Up @@ -233,7 +233,7 @@ public function testLoadSimpleSingleConnection()
$this->assertEquals('create', $definition->getFactoryMethod());

$this->assertDICConstructorArguments($definition, array(
new Reference('database_connection'), new Reference('doctrine.orm.default_configuration')
new Reference('doctrine.dbal.default_connection'), new Reference('doctrine.orm.default_configuration')
));
}

Expand Down

0 comments on commit f7808de

Please sign in to comment.