| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\Translation\DependencyInjection; |
| 13 |
|
| 14 |
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
| 15 |
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; |
| 16 |
use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 17 |
use Symfony\Component\DependencyInjection\Reference; |
| 18 |
|
| 19 |
class TranslatorPass implements CompilerPassInterface |
| 20 |
{ |
| 21 |
public function process(ContainerBuilder $container): void |
| 22 |
{ |
| 23 |
if (!$container->hasDefinition('translator.default')) { |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
$loaders = []; |
| 28 |
$loaderRefs = []; |
| 29 |
foreach ($container->findTaggedServiceIds('translation.loader', true) as $id => $attributes) { |
| 30 |
$loaderRefs[$id] = new Reference($id); |
| 31 |
$loaders[$id][] = $attributes[0]['alias']; |
| 32 |
if (isset($attributes[0]['legacy-alias'])) { |
| 33 |
$loaders[$id][] = $attributes[0]['legacy-alias']; |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
if ($container->hasDefinition('translation.reader')) { |
| 38 |
$definition = $container->getDefinition('translation.reader'); |
| 39 |
foreach ($loaders as $id => $formats) { |
| 40 |
foreach ($formats as $format) { |
| 41 |
$definition->addMethodCall('addLoader', [$format, $loaderRefs[$id]]); |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
$container |
| 47 |
->findDefinition('translator.default') |
| 48 |
->replaceArgument(0, ServiceLocatorTagPass::register($container, $loaderRefs)) |
| 49 |
->replaceArgument(3, $loaders) |
| 50 |
; |
| 51 |
|
| 52 |
if ($container->hasDefinition('validator') && $container->hasDefinition('translation.extractor.visitor.constraint')) { |
| 53 |
$constraintVisitorDefinition = $container->getDefinition('translation.extractor.visitor.constraint'); |
| 54 |
$constraintClassNames = []; |
| 55 |
|
| 56 |
foreach ($container->getDefinitions() as $definition) { |
| 57 |
if (!$definition->hasTag('validator.constraint_validator')) { |
| 58 |
continue; |
| 59 |
} |
| 60 |
|
| 61 |
$className = $container->getParameterBag()->resolveValue($definition->getClass()); |
| 62 |
|
| 63 |
$constraintClassNames[] = str_replace('Validator', '', substr(strrchr($className, '\\'), 1)); |
| 64 |
} |
| 65 |
|
| 66 |
$constraintVisitorDefinition->setArgument(0, $constraintClassNames); |
| 67 |
} |
| 68 |
|
| 69 |
if (!$container->hasParameter('twig.default_path')) { |
| 70 |
return; |
| 71 |
} |
| 72 |
|
| 73 |
$paths = array_keys($container->getDefinition('twig.template_iterator')->getArgument(1)); |
| 74 |
if ($container->hasDefinition('console.command.translation_debug')) { |
| 75 |
$definition = $container->getDefinition('console.command.translation_debug'); |
| 76 |
$definition->replaceArgument(4, $container->getParameter('twig.default_path')); |
| 77 |
|
| 78 |
if (\count($definition->getArguments()) > 6) { |
| 79 |
$definition->replaceArgument(6, $paths); |
| 80 |
} |
| 81 |
} |
| 82 |
if ($container->hasDefinition('console.command.translation_extract')) { |
| 83 |
$definition = $container->getDefinition('console.command.translation_extract'); |
| 84 |
$definition->replaceArgument(5, $container->getParameter('twig.default_path')); |
| 85 |
|
| 86 |
if (\count($definition->getArguments()) > 7) { |
| 87 |
$definition->replaceArgument(7, $paths); |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
} |