RegisterFileLoadersPass::process()   B
last analyzed

Complexity

Conditions 6
Paths 10

Size

Total Lines 43
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 8.439
c 0
b 0
f 0
ccs 26
cts 26
cp 1
cc 6
eloc 20
nc 10
nop 1
crap 6
1
<?php
2
3
/*
4
 * This file is part of the AsmTranslationLoaderBundle package.
5
 *
6
 * (c) Marc Aschmann <[email protected]>
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 Asm\TranslationLoaderBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
class RegisterFileLoadersPass implements CompilerPassInterface
19
{
20
    /**
21
     * {@inheritDoc}
22
     */
23 16
    public function process(ContainerBuilder $container)
24
    {
25 16
        if (!$container->hasDefinition('asm_translation_loader.file_loader_resolver')) {
26 1
            return;
27
        }
28
29 15
        $resolver = $container->getDefinition('asm_translation_loader.file_loader_resolver');
30 15
        $loaders  = $container->findTaggedServiceIds('translation.loader');
31
32 15
        foreach ($loaders as $id => $tagAttributes) {
33
            /**
34
             * At this point there is no means to identify the type of loader we have, so we use
35
             * all tagged loaders to fill the resolver.
36
             * Also we need to add the references, since we cannot make sure the services are
37
             * already instantiated
38
             */
39 15
            foreach ($tagAttributes as $attributes) {
40
                /** @var \Symfony\Component\Translation\Loader\LoaderInterface $loader */
41 15
                $resolver->addMethodCall(
42 15
                    'registerLoader',
43
                    array(
44 15
                        new Reference($id),
45 15
                        $attributes['alias']
46 15
                    )
47 15
                );
48 15
            }
49 15
        }
50
51
        // additional file loaders can be registered in the configuration
52 15
        if ($container->hasParameter('asm_translation_loader.translation_loaders')) {
53 4
            $additionalLoaders = $container->getParameter('asm_translation_loader.translation_loaders');
54
55 4
            foreach ($additionalLoaders as $extension => $loaderId) {
56 2
                $resolver->addMethodCall(
57 2
                    'registerLoader',
58
                    array(
59 2
                        new Reference($loaderId),
60
                        $extension
61 2
                    )
62 2
                );
63 4
            }
64 4
        }
65 15
    }
66
}
67