|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sonata Project package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sonata\EasyExtendsBundle\DependencyInjection\Compiler; |
|
13
|
|
|
|
|
14
|
|
|
use Sonata\EasyExtendsBundle\Mapper\DoctrineCollector; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author Thomas Rabaix <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class AddMapperInformationCompilerPass implements CompilerPassInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
*/ |
|
26
|
|
|
public function process(ContainerBuilder $container) |
|
27
|
|
|
{ |
|
28
|
|
|
if (!$container->hasDefinition('doctrine')) { |
|
29
|
|
|
$container->removeDefinition('sonata.easy_extends.doctrine.mapper'); |
|
30
|
|
|
|
|
31
|
|
|
return; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
$mapper = $container->getDefinition('sonata.easy_extends.doctrine.mapper'); |
|
35
|
|
|
|
|
36
|
|
|
foreach (DoctrineCollector::getInstance()->getAssociations() as $class => $associations) { |
|
37
|
|
|
foreach ($associations as $field => $options) { |
|
38
|
|
|
$mapper->addMethodCall('addAssociation', array($class, $field, $options)); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
foreach (DoctrineCollector::getInstance()->getDiscriminatorColumns() as $class => $columnDefinition) { |
|
43
|
|
|
$mapper->addMethodCall('addDiscriminatorColumn', array($class, $columnDefinition)); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
foreach (DoctrineCollector::getInstance()->getDiscriminators() as $class => $discriminators) { |
|
47
|
|
|
foreach ($discriminators as $key => $discriminatorClass) { |
|
48
|
|
|
$mapper->addMethodCall('addDiscriminator', array($class, $key, $discriminatorClass)); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
foreach (DoctrineCollector::getInstance()->getInheritanceTypes() as $class => $type) { |
|
53
|
|
|
$mapper->addMethodCall('addInheritanceType', array($class, $type)); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
foreach (DoctrineCollector::getInstance()->getIndexes() as $class => $indexes) { |
|
57
|
|
|
foreach ($indexes as $field => $options) { |
|
58
|
|
|
$mapper->addMethodCall('addIndex', array($class, $field, $options)); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
foreach (DoctrineCollector::getInstance()->getUniques() as $class => $uniques) { |
|
63
|
|
|
foreach ($uniques as $field => $options) { |
|
64
|
|
|
$mapper->addMethodCall('addUnique', array($class, $field, $options)); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|