TranslatorCompilerPass::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the AfDontTranslateBundle package
5
 *
6
 * (c) Antoine Froger <[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 Af\Bundle\DontTranslateBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Definition;
17
use Symfony\Component\DependencyInjection\Reference;
18
19
/**
20
 * Class TranslatorCompilerPass
21
 * @package Af\Bundle\DontTranslateBundle\DependencyInjection\Compiler
22
 *
23
 * @author Antoine Froger <[email protected]>
24
 */
25
class TranslatorCompilerPass implements CompilerPassInterface
26
{
27
    public function process(ContainerBuilder $container)
28
    {
29
        if (!$container->hasDefinition('translator.default')) {
30
            return;
31
        }
32
33
        // Saves the translator.default service under another name
34
        $container->setDefinition(
35
            'translator.main',
36
            $container->getDefinition('translator.default')
37
        );
38
39
        // Overrides the translator.default service by the AfDontTranslate Translator
40
        // and injects it the previous translator.default service
41
        $container->setDefinition('translator.default', new Definition(
42
            'Af\Bundle\DontTranslateBundle\Translation\Translator',
43
            array(new Reference('translator.main'))
44
        ));
45
    }
46
}
47