Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/translation/DependencyInjection/TranslatorPass.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is part of the Symfony package. | |
5 * | |
6 * (c) Fabien Potencier <fabien@symfony.com> | |
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 Symfony\Component\Translation\DependencyInjection; | |
13 | |
14 use Symfony\Component\DependencyInjection\Reference; | |
15 use Symfony\Component\DependencyInjection\ContainerBuilder; | |
16 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | |
17 use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; | |
18 | |
19 class TranslatorPass implements CompilerPassInterface | |
20 { | |
21 private $translatorServiceId; | |
22 private $readerServiceId; | |
23 private $loaderTag; | |
24 private $debugCommandServiceId; | |
25 private $updateCommandServiceId; | |
26 | |
27 public function __construct($translatorServiceId = 'translator.default', $readerServiceId = 'translation.loader', $loaderTag = 'translation.loader', $debugCommandServiceId = 'console.command.translation_debug', $updateCommandServiceId = 'console.command.translation_update') | |
28 { | |
29 if ('translation.loader' === $readerServiceId && 2 > func_num_args()) { | |
30 @trigger_error('The default value for $readerServiceId will change in 4.0 to "translation.reader".', E_USER_DEPRECATED); | |
31 } | |
32 | |
33 $this->translatorServiceId = $translatorServiceId; | |
34 $this->readerServiceId = $readerServiceId; | |
35 $this->loaderTag = $loaderTag; | |
36 $this->debugCommandServiceId = $debugCommandServiceId; | |
37 $this->updateCommandServiceId = $updateCommandServiceId; | |
38 } | |
39 | |
40 public function process(ContainerBuilder $container) | |
41 { | |
42 if (!$container->hasDefinition($this->translatorServiceId)) { | |
43 return; | |
44 } | |
45 | |
46 $loaders = array(); | |
47 $loaderRefs = array(); | |
48 foreach ($container->findTaggedServiceIds($this->loaderTag, true) as $id => $attributes) { | |
49 $loaderRefs[$id] = new Reference($id); | |
50 $loaders[$id][] = $attributes[0]['alias']; | |
51 if (isset($attributes[0]['legacy-alias'])) { | |
52 $loaders[$id][] = $attributes[0]['legacy-alias']; | |
53 } | |
54 } | |
55 | |
56 if ($container->hasDefinition($this->readerServiceId)) { | |
57 $definition = $container->getDefinition($this->readerServiceId); | |
58 foreach ($loaders as $id => $formats) { | |
59 foreach ($formats as $format) { | |
60 $definition->addMethodCall('addLoader', array($format, $loaderRefs[$id])); | |
61 } | |
62 } | |
63 } | |
64 | |
65 // Duplicated code to support "translation.reader", to be removed in 4.0 | |
66 if ('translation.reader' !== $this->readerServiceId) { | |
67 if ($container->hasDefinition('translation.reader')) { | |
68 $definition = $container->getDefinition('translation.reader'); | |
69 foreach ($loaders as $id => $formats) { | |
70 foreach ($formats as $format) { | |
71 $definition->addMethodCall('addLoader', array($format, $loaderRefs[$id])); | |
72 } | |
73 } | |
74 } | |
75 } | |
76 | |
77 $container | |
78 ->findDefinition($this->translatorServiceId) | |
79 ->replaceArgument(0, ServiceLocatorTagPass::register($container, $loaderRefs)) | |
80 ->replaceArgument(3, $loaders) | |
81 ; | |
82 | |
83 if (!$container->hasParameter('twig.default_path')) { | |
84 return; | |
85 } | |
86 | |
87 if ($container->hasDefinition($this->debugCommandServiceId)) { | |
88 $container->getDefinition($this->debugCommandServiceId)->replaceArgument(4, $container->getParameter('twig.default_path')); | |
89 } | |
90 | |
91 if ($container->hasDefinition($this->updateCommandServiceId)) { | |
92 $container->getDefinition($this->updateCommandServiceId)->replaceArgument(5, $container->getParameter('twig.default_path')); | |
93 } | |
94 } | |
95 } |