Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 200 | Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 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\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)
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->findTaggedServiceIds('validator.constraint_validator', true) as $id => $attributes) {
57
                $serviceDefinition = $container->getDefinition($id);
58
                // Extraction of the constraint class name from the Constraint Validator FQCN
59
                $constraintClassNames[] = str_replace('Validator', '', substr(strrchr($serviceDefinition->getClass(), '\\'), 1));
60
            }
61
 
62
            $constraintVisitorDefinition->setArgument(0, $constraintClassNames);
63
        }
64
 
65
        if (!$container->hasParameter('twig.default_path')) {
66
            return;
67
        }
68
 
69
        $paths = array_keys($container->getDefinition('twig.template_iterator')->getArgument(1));
70
        if ($container->hasDefinition('console.command.translation_debug')) {
71
            $definition = $container->getDefinition('console.command.translation_debug');
72
            $definition->replaceArgument(4, $container->getParameter('twig.default_path'));
73
 
74
            if (\count($definition->getArguments()) > 6) {
75
                $definition->replaceArgument(6, $paths);
76
            }
77
        }
78
        if ($container->hasDefinition('console.command.translation_extract')) {
79
            $definition = $container->getDefinition('console.command.translation_extract');
80
            $definition->replaceArgument(5, $container->getParameter('twig.default_path'));
81
 
82
            if (\count($definition->getArguments()) > 7) {
83
                $definition->replaceArgument(7, $paths);
84
            }
85
        }
86
    }
87
}