Completed
Push — master ( 79d213...eeff33 )
by Kamil
23:15
created

TranslatorLoaderProviderPass::process()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
rs 8.7972
cc 4
eloc 14
nc 4
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Bundle\ThemeBundle\Translation\DependencyInjection\Compiler;
13
14
use Sylius\Bundle\ThemeBundle\Translation\Loader\ThemeAwareLoader;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Reference;
18
19
/**
20
 * @author Kamil Kokot <[email protected]>
21
 */
22
final class TranslatorLoaderProviderPass implements CompilerPassInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function process(ContainerBuilder $container)
28
    {
29
        try {
30
            $loaderProvider = $container->findDefinition('sylius.theme.translation.loader_provider');
31
        } catch (\InvalidArgumentException $exception) {
32
            return;
33
        }
34
35
        $taggedServices = $container->findTaggedServiceIds('translation.loader');
36
        $loaders = [];
37
        foreach ($taggedServices as $id => $attributes) {
38
            $loader = $container->findDefinition($id);
39
            $loader->setLazy(true);
40
41
            $loaders[$attributes[0]['alias']] = new Reference($id);
42
43
            if (isset($attributes[0]['legacy-alias'])) {
44
                $loaders[$attributes[0]['legacy-alias']] = new Reference($id);
45
            }
46
        }
47
48
        $loaderProvider->replaceArgument(0, $loaders);
49
    }
50
}
51