1
|
|
|
<?php |
2
|
|
|
namespace Boekkooi\Bundle\JqueryValidationBundle\DependencyInjection\Compiler; |
3
|
|
|
|
4
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
6
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @author Warnar Boekkooi <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
class ExtensionPass implements CompilerPassInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* {@inheritDoc} |
15
|
|
|
*/ |
16
|
|
|
public function process(ContainerBuilder $container) |
17
|
|
|
{ |
18
|
|
|
$this->registerRuleProcessors($container); |
19
|
|
|
$this->registerRuleCompilers($container); |
20
|
|
|
$this->registerRuleMappers($container); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param ContainerBuilder $container |
25
|
|
|
*/ |
26
|
|
|
protected function registerRuleProcessors(ContainerBuilder $container) |
27
|
|
|
{ |
28
|
|
|
if (!$container->hasDefinition('boekkooi.jquery_validation.rule_processor')) { |
29
|
|
|
return; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$passes = new \SplPriorityQueue(); |
33
|
|
|
$order = PHP_INT_MAX; |
34
|
|
|
foreach ($container->findTaggedServiceIds('form_rule_processor') as $id => $attr) { |
35
|
|
|
$priority = isset($attr[0]['priority']) ? $attr[0]['priority'] : 0; |
36
|
|
|
|
37
|
|
|
$passes->insert($id, array($priority, --$order)); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$references = array(); |
41
|
|
|
foreach ($passes as $id) { |
42
|
|
|
$references[] = new Reference($id); |
43
|
|
|
} |
44
|
|
|
$container->getDefinition('boekkooi.jquery_validation.rule_processor')->replaceArgument(0, $references); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param ContainerBuilder $container |
49
|
|
|
*/ |
50
|
|
|
protected function registerRuleCompilers(ContainerBuilder $container) |
51
|
|
|
{ |
52
|
|
|
if (!$container->hasDefinition('boekkooi.jquery_validation.rule_compiler')) { |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$passes = new \SplPriorityQueue(); |
57
|
|
|
$order = PHP_INT_MAX; |
58
|
|
|
foreach ($container->findTaggedServiceIds('form_rule_compiler') as $id => $attr) { |
59
|
|
|
$priority = isset($attr[0]['priority']) ? $attr[0]['priority'] : 0; |
60
|
|
|
|
61
|
|
|
$passes->insert($id, array($priority, --$order)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$references = array(); |
65
|
|
|
foreach ($passes as $id) { |
66
|
|
|
$references[] = new Reference($id); |
67
|
|
|
} |
68
|
|
|
$container->getDefinition('boekkooi.jquery_validation.rule_compiler')->replaceArgument(0, $references); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param ContainerBuilder $container |
73
|
|
|
* @return array|null |
74
|
|
|
*/ |
75
|
|
|
protected function registerRuleMappers(ContainerBuilder $container) |
76
|
|
|
{ |
77
|
|
|
if (!$container->hasDefinition('boekkooi.jquery_validation.form.rule.processor.constraint_mapper')) { |
78
|
|
|
return; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$mappers = $container->findTaggedServiceIds('form_rule_constraint_mapper'); |
82
|
|
|
$resolverDef = $container->getDefinition('boekkooi.jquery_validation.form.rule.processor.constraint_mapper'); |
83
|
|
|
foreach ($mappers as $id => $attr) { |
84
|
|
|
$resolverDef->addMethodCall('addMapper', array(new Reference($id))); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|