forked from symfony-cmf/routing-auto-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CmfRoutingAutoBundle.php
125 lines (112 loc) · 4.68 KB
/
CmfRoutingAutoBundle.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2015 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Bundle\RoutingAutoBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass;
use Symfony\Cmf\Bundle\RoutingAutoBundle\DependencyInjection\Compiler\ServicePass;
use Symfony\Cmf\Bundle\RoutingAutoBundle\DependencyInjection\Compiler\AdapterPass;
class CmfRoutingAutoBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new ServicePass());
$container->addCompilerPass(new AdapterPass());
$this->buildPhpcrCompilerPass($container);
$this->buildOrmCompilerPass($container);
}
/**
* Creates and registers compiler passes for PHPCR-ODM mapping if both the
* phpcr-odm and the phpcr-bundle are present.
*
* @param ContainerBuilder $container
*/
private function buildPhpcrCompilerPass(ContainerBuilder $container)
{
if (!class_exists('Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass')
|| !class_exists('Doctrine\ODM\PHPCR\Version')
) {
return;
}
$bundles = $container->getParameter('kernel.bundles');
if (isset($bundles['CmfRoutingBundle'])) {
$container->addCompilerPass(
DoctrinePhpcrMappingsPass::createXmlMappingDriver(
array(
realpath(
__DIR__.'/Resources/config/doctrine-model'
) => 'Symfony\Cmf\Bundle\RoutingAutoBundle\Model',
),
array('cmf_routing_auto.persistence.phpcr.manager_name'),
false,
array('CmfRoutingAutoBundle' => 'Symfony\Cmf\Bundle\RoutingAutoBundle\Model')
)
);
}
}
/**
* Creates and registers compiler passes for ORM mappings if both doctrine
* ORM and a suitable compiler pass implementation are available.
*
* @param ContainerBuilder $container
*/
private function buildOrmCompilerPass(ContainerBuilder $container)
{
if (!class_exists('Doctrine\ORM\Version')) {
return;
}
$doctrineOrmCompiler = $this->findDoctrineOrmCompiler();
if (!$doctrineOrmCompiler) {
return;
}
$bundles = $container->getParameter('kernel.bundles');
if (isset($bundles['CmfRoutingBundle'])) {
$container->addCompilerPass(
$doctrineOrmCompiler::createXmlMappingDriver(
array(
realpath(
__DIR__.'/Resources/config/doctrine-inherit'
) => 'Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm',
realpath(
__DIR__.'/Resources/config/doctrine-orm'
) => 'Symfony\Cmf\Bundle\RoutingAutoBundle\Doctrine\Orm',
),
array('cmf_routing_auto.dynamic.persistence.orm.manager_name'),
'cmf_routing.backend_type_orm',
array(
'CmfRoutingBundle' => 'Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm',
'CmfRoutingAutoBundle' => 'Symfony\Cmf\Bundle\RoutingAutoBundle\Doctrine\Orm'
)
)
);
}
}
/**
* Looks for a mapping compiler pass. If available, use the one from
* DoctrineBundle (available only since DoctrineBundle 2.4 and Symfony 2.3)
* Otherwise use the standalone one from CmfCoreBundle.
*
* @return boolean|string the compiler pass to use or false if no suitable
* one was found
*/
private function findDoctrineOrmCompiler()
{
if (class_exists('Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterMappingsPass')
&& class_exists('Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')
) {
return 'Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass';
}
if (class_exists('Symfony\Cmf\Bundle\CoreBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')) {
return 'Symfony\Cmf\Bundle\CoreBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass';
}
return false;
}
}