Completed
Push — EZP-26835-load-translation-pac... ( f96c61 )
by Nicolas
15:15
created

TranslationPass   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 16 3
1
<?php
2
3
/**
4
 * File containing the TranslationPass class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler;
10
11
use eZ\Bundle\EzPublishCoreBundle\Translation\Collector;
12
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
15
/**
16
 * This compilation pass loads every ezplatform available translations into symfony translator
17
 */
18
class TranslationPass implements CompilerPassInterface
19
{
20
    public function process(ContainerBuilder $container)
21
    {
22
        if (!$container->hasDefinition('translator.default')) {
23
            return;
24
        }
25
26
        $definition = $container->getDefinition('translator.default');
27
        $collector = new Collector($container->getParameterBag()->get('kernel.root_dir'));
28
29
        foreach ($collector->collect() as $file) {
30
            $definition->addMethodCall(
31
                'addResource',
32
                array($file['format'], $file['file'], $file['locale'], $file['domain'])
33
            );
34
        }
35
    }
36
}
37