|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Admingenerator\GeneratorBundle\DependencyInjection\Compiler; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
9
|
|
|
|
|
10
|
|
|
class ValidatorPass implements CompilerPassInterface |
|
11
|
|
|
{ |
|
12
|
|
|
public function process(ContainerBuilder $container) |
|
13
|
|
|
{ |
|
14
|
|
|
$taggedServices = $container->findTaggedServiceIds( |
|
15
|
|
|
'admingenerator.validator' |
|
16
|
|
|
); |
|
17
|
|
|
|
|
18
|
|
|
$taggedServicesPropel = $container->findTaggedServiceIds( |
|
19
|
|
|
'admingenerator.validator.propel' |
|
20
|
|
|
); |
|
21
|
|
|
|
|
22
|
|
|
$taggedServicesDoctrine = $container->findTaggedServiceIds( |
|
23
|
|
|
'admingenerator.validator.doctrine' |
|
24
|
|
|
); |
|
25
|
|
|
|
|
26
|
|
|
$taggedServicesDoctrineOdm = $container->findTaggedServiceIds( |
|
27
|
|
|
'admingenerator.validator.doctrine_odm' |
|
28
|
|
|
); |
|
29
|
|
|
|
|
30
|
|
|
if ($container->hasDefinition('admingenerator.generator.propel')) { |
|
31
|
|
|
$this->addValidators($taggedServicesPropel, $container->getDefinition('admingenerator.generator.propel')); |
|
32
|
|
|
$this->addValidators($taggedServices, $container->getDefinition('admingenerator.generator.propel')); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
if ($container->hasDefinition('admingenerator.generator.doctrine')) { |
|
36
|
|
|
$this->addValidators($taggedServicesDoctrine, $container->getDefinition('admingenerator.generator.doctrine')); |
|
37
|
|
|
$this->addValidators($taggedServices, $container->getDefinition('admingenerator.generator.doctrine')); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
if ($container->hasDefinition('admingenerator.generator.doctrine_odm')) { |
|
41
|
|
|
$this->addValidators($taggedServicesDoctrineOdm, $container->getDefinition('admingenerator.generator.doctrine_odm')); |
|
42
|
|
|
$this->addValidators($taggedServices, $container->getDefinition('admingenerator.generator.doctrine_odm')); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function addValidators(array $taggedServices, Definition $definition) |
|
47
|
|
|
{ |
|
48
|
|
|
foreach ($taggedServices as $id => $attributes) { |
|
49
|
|
|
$definition->addMethodCall( |
|
50
|
|
|
'addValidator', |
|
51
|
|
|
array(new Reference($id)) |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|