Skip to content

Commit 142233c

Browse files
committed
Merge pull request #137 from raindropdevs/master
fix: uses doctrine mapping compiler when CoreBundle is not installed
2 parents 741ff58 + 62dd0ec commit 142233c

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

CmfRoutingBundle.php

Lines changed: 29 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,35 @@ public function build(ContainerBuilder $container)
5557
}
5658
}
5759

58-
private function buildBaseOrmCompilerPass()
60+
/**
61+
* Searches a mapping compiler (doctrine bridge compiler is missing in symfony < 2.3).
62+
* Use Cmf\CoreBundle in that case.
63+
*/
64+
private function findDoctrineOrmCompiler()
65+
{
66+
$symfonyVersion = class_exists('Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterMappingsPass');
67+
68+
if ($symfonyVersion && class_exists('Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')) {
69+
return 'Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass';
70+
}
71+
72+
if (class_exists('Symfony\Cmf\Bundle\CoreBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')) {
73+
return 'Symfony\Cmf\Bundle\CoreBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass';
74+
}
75+
76+
return false;
77+
}
78+
79+
/**
80+
* Instantiate compiler now because of SymfonyFileLocator namespace issue (see phpcr method comment).
81+
*/
82+
private function buildBaseOrmCompilerPass($doctrineOrmCompiler)
5983
{
6084
$arguments = array(array(realpath(__DIR__ . '/Resources/config/doctrine-base')), '.orm.xml');
6185
$locator = new Definition('Doctrine\Common\Persistence\Mapping\Driver\DefaultFileLocator', $arguments);
6286
$driver = new Definition('Doctrine\ORM\Mapping\Driver\XmlDriver', array($locator));
6387

64-
return new DoctrineOrmMappingsPass(
88+
return new $doctrineOrmCompiler(
6589
$driver,
6690
array('Symfony\Component\Routing'),
6791
array('cmf_routing.dynamic.persistence.orm.manager_name'),

0 commit comments

Comments
 (0)