annotate vendor/symfony/translation/DependencyInjection/TranslatorPass.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children a9cd425dd02b
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of the Symfony package.
Chris@0 5 *
Chris@0 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Symfony\Component\Translation\DependencyInjection;
Chris@0 13
Chris@0 14 use Symfony\Component\DependencyInjection\Reference;
Chris@0 15 use Symfony\Component\DependencyInjection\ContainerBuilder;
Chris@0 16 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
Chris@0 17 use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
Chris@0 18
Chris@0 19 class TranslatorPass implements CompilerPassInterface
Chris@0 20 {
Chris@0 21 private $translatorServiceId;
Chris@0 22 private $readerServiceId;
Chris@0 23 private $loaderTag;
Chris@0 24 private $debugCommandServiceId;
Chris@0 25 private $updateCommandServiceId;
Chris@0 26
Chris@0 27 public function __construct($translatorServiceId = 'translator.default', $readerServiceId = 'translation.loader', $loaderTag = 'translation.loader', $debugCommandServiceId = 'console.command.translation_debug', $updateCommandServiceId = 'console.command.translation_update')
Chris@0 28 {
Chris@0 29 if ('translation.loader' === $readerServiceId && 2 > func_num_args()) {
Chris@0 30 @trigger_error('The default value for $readerServiceId will change in 4.0 to "translation.reader".', E_USER_DEPRECATED);
Chris@0 31 }
Chris@0 32
Chris@0 33 $this->translatorServiceId = $translatorServiceId;
Chris@0 34 $this->readerServiceId = $readerServiceId;
Chris@0 35 $this->loaderTag = $loaderTag;
Chris@0 36 $this->debugCommandServiceId = $debugCommandServiceId;
Chris@0 37 $this->updateCommandServiceId = $updateCommandServiceId;
Chris@0 38 }
Chris@0 39
Chris@0 40 public function process(ContainerBuilder $container)
Chris@0 41 {
Chris@0 42 if (!$container->hasDefinition($this->translatorServiceId)) {
Chris@0 43 return;
Chris@0 44 }
Chris@0 45
Chris@0 46 $loaders = array();
Chris@0 47 $loaderRefs = array();
Chris@0 48 foreach ($container->findTaggedServiceIds($this->loaderTag, true) as $id => $attributes) {
Chris@0 49 $loaderRefs[$id] = new Reference($id);
Chris@0 50 $loaders[$id][] = $attributes[0]['alias'];
Chris@0 51 if (isset($attributes[0]['legacy-alias'])) {
Chris@0 52 $loaders[$id][] = $attributes[0]['legacy-alias'];
Chris@0 53 }
Chris@0 54 }
Chris@0 55
Chris@0 56 if ($container->hasDefinition($this->readerServiceId)) {
Chris@0 57 $definition = $container->getDefinition($this->readerServiceId);
Chris@0 58 foreach ($loaders as $id => $formats) {
Chris@0 59 foreach ($formats as $format) {
Chris@0 60 $definition->addMethodCall('addLoader', array($format, $loaderRefs[$id]));
Chris@0 61 }
Chris@0 62 }
Chris@0 63 }
Chris@0 64
Chris@0 65 // Duplicated code to support "translation.reader", to be removed in 4.0
Chris@0 66 if ('translation.reader' !== $this->readerServiceId) {
Chris@0 67 if ($container->hasDefinition('translation.reader')) {
Chris@0 68 $definition = $container->getDefinition('translation.reader');
Chris@0 69 foreach ($loaders as $id => $formats) {
Chris@0 70 foreach ($formats as $format) {
Chris@0 71 $definition->addMethodCall('addLoader', array($format, $loaderRefs[$id]));
Chris@0 72 }
Chris@0 73 }
Chris@0 74 }
Chris@0 75 }
Chris@0 76
Chris@0 77 $container
Chris@0 78 ->findDefinition($this->translatorServiceId)
Chris@0 79 ->replaceArgument(0, ServiceLocatorTagPass::register($container, $loaderRefs))
Chris@0 80 ->replaceArgument(3, $loaders)
Chris@0 81 ;
Chris@0 82
Chris@0 83 if (!$container->hasParameter('twig.default_path')) {
Chris@0 84 return;
Chris@0 85 }
Chris@0 86
Chris@0 87 if ($container->hasDefinition($this->debugCommandServiceId)) {
Chris@0 88 $container->getDefinition($this->debugCommandServiceId)->replaceArgument(4, $container->getParameter('twig.default_path'));
Chris@0 89 }
Chris@0 90
Chris@0 91 if ($container->hasDefinition($this->updateCommandServiceId)) {
Chris@0 92 $container->getDefinition($this->updateCommandServiceId)->replaceArgument(5, $container->getParameter('twig.default_path'));
Chris@0 93 }
Chris@0 94 }
Chris@0 95 }