|
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 SetNotFoundLocaleResolverPass implements CompilerPassInterface |
|
21
|
|
|
{ |
|
22
|
|
|
const TWIG_EXTENSION_ID = 'benat_espina_i18n_routing.twig.current_path_translation_extension'; |
|
23
|
|
|
const LISTENER_ID = 'benat_espina_i18n_routing.event_listener.not_found_locale'; |
|
24
|
|
|
|
|
25
|
|
|
public function process(ContainerBuilder $container) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->loadDependency($container, self::LISTENER_ID, 0); |
|
28
|
|
|
$this->loadDependency($container, self::TWIG_EXTENSION_ID, 3); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
private function loadDependency(ContainerBuilder $container, $serviceId, $position) |
|
32
|
|
|
{ |
|
33
|
|
|
if (!$container->hasDefinition($serviceId)) { |
|
34
|
|
|
return; |
|
35
|
|
|
} |
|
36
|
|
|
$services = $container->findTaggedServiceIds('benat_espina_i18n_routing.not_found_locale_resolver'); |
|
37
|
|
|
|
|
38
|
|
|
if (0 === count($services)) { |
|
39
|
|
|
$container->findDefinition($serviceId)->replaceArgument( |
|
40
|
|
|
0, |
|
41
|
|
|
$container->getDefinition( |
|
42
|
|
|
'benat_espina_i18n_routing.resolver.not_found_locale.empty' |
|
43
|
|
|
) |
|
44
|
|
|
); |
|
45
|
|
|
|
|
46
|
|
|
return; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if (count($services) > 1) { |
|
50
|
|
|
throw new \LogicException( |
|
51
|
|
|
'Only one service can have the "benat_espina_i18n_routing.not_found_locale_resolver" tag.' |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$container->findDefinition($serviceId)->replaceArgument($position, $container->getDefinition(key($services))); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|