@@ -40,10 +40,12 @@ public function build(ContainerBuilder $container)
40
40
);
41
41
}
42
42
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 ));
45
47
$ container ->addCompilerPass (
46
- DoctrineOrmMappingsPass ::createXmlMappingDriver (
48
+ $ doctrineOrmCompiler ::createXmlMappingDriver (
47
49
array (
48
50
realpath (__DIR__ . '/Resources/config/doctrine-model ' ) => 'Symfony\Cmf\Bundle\RoutingBundle\Model ' ,
49
51
realpath (__DIR__ . '/Resources/config/doctrine-orm ' ) => 'Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm ' ,
@@ -55,13 +57,35 @@ public function build(ContainerBuilder $container)
55
57
}
56
58
}
57
59
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 )
59
83
{
60
84
$ arguments = array (array (realpath (__DIR__ . '/Resources/config/doctrine-base ' )), '.orm.xml ' );
61
85
$ locator = new Definition ('Doctrine\Common\Persistence\Mapping\Driver\DefaultFileLocator ' , $ arguments );
62
86
$ driver = new Definition ('Doctrine\ORM\Mapping\Driver\XmlDriver ' , array ($ locator ));
63
87
64
- return new DoctrineOrmMappingsPass (
88
+ return new $ doctrineOrmCompiler (
65
89
$ driver ,
66
90
array ('Symfony\Component\Routing ' ),
67
91
array ('cmf_routing.dynamic.persistence.orm.manager_name ' ),
0 commit comments