TranslatorCompilerPass   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 19 2
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