Passed
Push — master ( 10d6b0...a985d1 )
by Pierre
08:03
created

SymfonyCompilerPass::setFileLoader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Guzzle\ConfigOperationsBundle\DependencyInjection\CompilerPass;
4
5
use Symfony\Component\Config\FileLocator;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Loader;
9
use Symfony\Component\Serializer\Serializer;
10
11
class SymfonyCompilerPass implements CompilerPassInterface
12
{
13
    /**
14
     * @var Loader\YamlFileLoader
15
     */
16
    private $loader;
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function process(ContainerBuilder $container)
22
    {
23
        if ($container->hasDefinition('serializer')
24
            && $container->getDefinition('serializer')->getClass() === Serializer::class) {
25
            $this->getFileLoader($container)->load('symfony_normalizer.yml');
26
        }
27
    }
28
29
    /**
30
     * @param ContainerBuilder $container
31
     *
32
     * @return Loader\YamlFileLoader
33
     */
34
    public function getFileLoader(ContainerBuilder $container)
35
    {
36
        if (!$this->loader) {
37
            $this->loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../../Resources/config'));
38
        }
39
40
        return $this->loader;
41
    }
42
43
    /**
44
     * @param Loader\YamlFileLoader $loader
45
     */
46
    public function setFileLoader(Loader\YamlFileLoader $loader)
47
    {
48
        $this->loader = $loader;
49
    }
50
}
51