Skip to content

Commit 5782e79

Browse files
fix: doctrine orm compiler - tries CoreBundle and fallback on Doctrine native
1 parent cf909e4 commit 5782e79

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

CmfRoutingBundle.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ public function build(ContainerBuilder $container)
4040
);
4141
}
4242

43-
if (class_exists('Symfony\Cmf\Bundle\CoreBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')) {
44-
$container->addCompilerPass($this->buildBaseOrmCompilerPass());
43+
$doctrineOrmCompiler = $this->findDoctrineOrmCompiler();
44+
45+
if ($doctrineOrmCompiler) {
46+
$container->addCompilerPass($this->buildBaseOrmCompilerPass($doctrineOrmCompiler));
4547
$container->addCompilerPass(
46-
DoctrineOrmMappingsPass::createXmlMappingDriver(
48+
$doctrineOrmCompiler::createXmlMappingDriver(
4749
array(
4850
realpath(__DIR__ . '/Resources/config/doctrine-model') => 'Symfony\Cmf\Bundle\RoutingBundle\Model',
4951
realpath(__DIR__ . '/Resources/config/doctrine-orm') => 'Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm',
@@ -55,13 +57,29 @@ public function build(ContainerBuilder $container)
5557
}
5658
}
5759

58-
private function buildBaseOrmCompilerPass()
60+
/**
61+
* Searches a mapping compiler: try cmf CoreBundle first and fallback on DoctrineBundle.
62+
*/
63+
private function findDoctrineOrmCompiler()
64+
{
65+
if (class_exists('Symfony\Cmf\Bundle\CoreBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')) {
66+
return 'Symfony\Cmf\Bundle\CoreBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass';
67+
}
68+
69+
if (class_exists('Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')) {
70+
return 'Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass';
71+
}
72+
73+
return false;
74+
}
75+
76+
private function buildBaseOrmCompilerPass($doctrineOrmCompiler)
5977
{
6078
$arguments = array(array(realpath(__DIR__ . '/Resources/config/doctrine-base')), '.orm.xml');
6179
$locator = new Definition('Doctrine\Common\Persistence\Mapping\Driver\DefaultFileLocator', $arguments);
6280
$driver = new Definition('Doctrine\ORM\Mapping\Driver\XmlDriver', array($locator));
6381

64-
return new DoctrineOrmMappingsPass(
82+
return new $doctrineOrmCompiler(
6583
$driver,
6684
array('Symfony\Component\Routing'),
6785
array('cmf_routing.dynamic.persistence.orm.manager_name'),

0 commit comments

Comments
 (0)