Completed
Pull Request — master (#5)
by Dmitry
03:07
created

ExtensionLoadPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 9.4285
cc 3
eloc 4
nc 3
nop 1
crap 3
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