wp-user-avatar
/
third-party
/
vendor
/
symfony
/
translation
/
DependencyInjection
/
TranslatorPass.php
wp-user-avatar
/
third-party
/
vendor
/
symfony
/
translation
/
DependencyInjection
Last commit date
TranslationDumperPass.php
2 months ago
TranslationExtractorPass.php
2 months ago
TranslatorPass.php
2 months ago
TranslatorPathsPass.php
2 months ago
TranslatorPass.php
78 lines
| 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 | namespace ProfilePressVendor\Symfony\Component\Translation\DependencyInjection; |
| 12 | |
| 13 | use ProfilePressVendor\Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
| 14 | use ProfilePressVendor\Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; |
| 15 | use ProfilePressVendor\Symfony\Component\DependencyInjection\ContainerBuilder; |
| 16 | use ProfilePressVendor\Symfony\Component\DependencyInjection\Reference; |
| 17 | class TranslatorPass implements CompilerPassInterface |
| 18 | { |
| 19 | private $translatorServiceId; |
| 20 | private $readerServiceId; |
| 21 | private $loaderTag; |
| 22 | private $debugCommandServiceId; |
| 23 | private $updateCommandServiceId; |
| 24 | public function __construct(string $translatorServiceId = 'translator.default', string $readerServiceId = 'translation.reader', string $loaderTag = 'translation.loader', string $debugCommandServiceId = 'console.command.translation_debug', string $updateCommandServiceId = 'console.command.translation_extract') |
| 25 | { |
| 26 | if (0 < \func_num_args()) { |
| 27 | trigger_deprecation('symfony/translation', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); |
| 28 | } |
| 29 | $this->translatorServiceId = $translatorServiceId; |
| 30 | $this->readerServiceId = $readerServiceId; |
| 31 | $this->loaderTag = $loaderTag; |
| 32 | $this->debugCommandServiceId = $debugCommandServiceId; |
| 33 | $this->updateCommandServiceId = $updateCommandServiceId; |
| 34 | } |
| 35 | public function process(ContainerBuilder $container) |
| 36 | { |
| 37 | if (!$container->hasDefinition($this->translatorServiceId)) { |
| 38 | return; |
| 39 | } |
| 40 | $loaders = []; |
| 41 | $loaderRefs = []; |
| 42 | foreach ($container->findTaggedServiceIds($this->loaderTag, \true) as $id => $attributes) { |
| 43 | $loaderRefs[$id] = new Reference($id); |
| 44 | $loaders[$id][] = $attributes[0]['alias']; |
| 45 | if (isset($attributes[0]['legacy-alias'])) { |
| 46 | $loaders[$id][] = $attributes[0]['legacy-alias']; |
| 47 | } |
| 48 | } |
| 49 | if ($container->hasDefinition($this->readerServiceId)) { |
| 50 | $definition = $container->getDefinition($this->readerServiceId); |
| 51 | foreach ($loaders as $id => $formats) { |
| 52 | foreach ($formats as $format) { |
| 53 | $definition->addMethodCall('addLoader', [$format, $loaderRefs[$id]]); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | $container->findDefinition($this->translatorServiceId)->replaceArgument(0, ServiceLocatorTagPass::register($container, $loaderRefs))->replaceArgument(3, $loaders); |
| 58 | if (!$container->hasParameter('twig.default_path')) { |
| 59 | return; |
| 60 | } |
| 61 | $paths = array_keys($container->getDefinition('twig.template_iterator')->getArgument(1)); |
| 62 | if ($container->hasDefinition($this->debugCommandServiceId)) { |
| 63 | $definition = $container->getDefinition($this->debugCommandServiceId); |
| 64 | $definition->replaceArgument(4, $container->getParameter('twig.default_path')); |
| 65 | if (\count($definition->getArguments()) > 6) { |
| 66 | $definition->replaceArgument(6, $paths); |
| 67 | } |
| 68 | } |
| 69 | if ($container->hasDefinition($this->updateCommandServiceId)) { |
| 70 | $definition = $container->getDefinition($this->updateCommandServiceId); |
| 71 | $definition->replaceArgument(5, $container->getParameter('twig.default_path')); |
| 72 | if (\count($definition->getArguments()) > 7) { |
| 73 | $definition->replaceArgument(7, $paths); |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 |