Completed
Push — master ( cbb910...10a99c )
by Dmitry
01:02
created

ExtensionLoadPass::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace SymfonyBundles\BundleDependency\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
9
class ExtensionLoadPass implements CompilerPassInterface
10
{
11
12
    /**
13
     * @var array
14
     */
15
    private $bundles;
16
17
    /**
18
     * @param array $bundles
19
     */
20 1
    public function __construct(array $bundles)
21
    {
22 1
        $this->bundles = $bundles;
23 1
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 1
    public function process(ContainerBuilder $container)
29
    {
30 1
        foreach ($this->bundles as $bundle) {
31 1
            if ($extension = $bundle->getContainerExtension()) {
32 1
                $this->loadExtension($extension, $container);
33 1
            }
34 1
        }
35 1
    }
36
37
    /**
38
     * @param Extension        $extension
39
     * @param ContainerBuilder $container
40
     *
41
     * @return void
42
     */
43 1
    private function loadExtension(Extension $extension, ContainerBuilder $container)
44
    {
45 1
        if (!$container->getExtensionConfig($extension->getAlias())) {
46 1
            $extension->load([], $container);
47 1
        }
48 1
    }
49
50
}
51