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

TranslationPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 1
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
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