1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the I18n Routing Bundle. |
5
|
|
|
* |
6
|
|
|
* (c) Beñat Espiña <[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 BenatEspina\I18nRoutingBundle\DependencyInjection\Compiler; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Beñat Espiña <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class RegistryParametersResolversPass implements CompilerPassInterface |
21
|
|
|
{ |
22
|
|
|
const SERVICE_ID = 'benat_espina_i18n_routing.resolver.parameters_resolver_registry'; |
23
|
|
|
|
24
|
|
|
public function process(ContainerBuilder $container) |
25
|
|
|
{ |
26
|
|
|
if (!$container->hasDefinition(self::SERVICE_ID)) { |
27
|
|
|
return; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
$config = $container->getParameter('benat_espina_i18n_routing.config'); |
31
|
|
|
$services = $container->findTaggedServiceIds('benat_espina_i18n_routing.parameters_resolver'); |
32
|
|
|
|
33
|
|
|
$parametersResolvers = []; |
34
|
|
|
foreach ($services as $serviceId => $tags) { |
35
|
|
|
foreach ($tags as $attributes) { |
36
|
|
|
if (!isset($attributes['alias'])) { |
37
|
|
|
throw new \LogicException( |
38
|
|
|
'All the services tagged by "benat_espina_i18n_routing.parameters_resolver" ' . |
39
|
|
|
'must have "alias" property' |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
if ($attributes['alias'] === $config['default_parameters_resolver']) { |
43
|
|
|
$container->findDefinition(self::SERVICE_ID)->replaceArgument( |
44
|
|
|
1, |
45
|
|
|
$container->getDefinition($serviceId) |
46
|
|
|
); |
47
|
|
|
continue; |
48
|
|
|
} |
49
|
|
|
$parametersResolvers[] = $container->getDefinition($serviceId); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
$container->findDefinition(self::SERVICE_ID)->replaceArgument( |
53
|
|
|
0, |
54
|
|
|
$parametersResolvers |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|