AddResourcePass::process()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.0534
c 0
b 0
f 0
ccs 17
cts 17
cp 1
cc 4
eloc 13
nc 4
nop 1
crap 4
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
/**
19
 * Compiler pass that adds additional resources to the Translator.
20
 *
21
 * @author Christian Flothmann <[email protected]>
22
 */
23
class AddResourcePass implements CompilerPassInterface
24
{
25
    /**
26
     * {@inheritDoc}
27
     */
28 8
    public function process(ContainerBuilder $container)
29
    {
30 8
        $resources = $container->getParameter('asm_translation_loader.resources');
31 8
        $translator = $container->findDefinition('translator.default');
32
33 8
        if (null !== $translator) {
34 6
            foreach ($resources as $locale => $domains) {
35 4
                foreach ($domains as $domain) {
36 4
                    $translator->addMethodCall(
37 4
                        'addResource',
38
                        array(
39 4
                            'db',
40 4
                            new Reference('asm_translation_loader.translation_manager_resource'),
41 4
                            $locale,
42 4
                            $domain,
43
                        )
44 4
                    );
45 4
                }
46 6
            }
47 6
        }
48 8
    }
49
}
50