Completed
Branch master (01610a)
by Arnaud
02:58
created

LAGAdminBundle::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 2
1
<?php
2
3
namespace LAG\AdminBundle;
4
5
use LAG\AdminBundle\DependencyInjection\DataProviderCompilerPass;
6
use LAG\AdminBundle\DependencyInjection\FieldCompilerPass;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
9
use Symfony\Component\HttpKernel\Bundle\Bundle;
10
11
class LAGAdminBundle extends Bundle
12
{
13
    /**
14
     * Add the field and the data provider compiler pass
15
     *
16
     * @param ContainerBuilder $container
17
     */
18
    public function build(ContainerBuilder $container)
19
    {
20
        parent::build($container);
21
22
        // register field compiler pass
23
        $container->addCompilerPass(new FieldCompilerPass());
24
        $container->addCompilerPass(new DataProviderCompilerPass());
25
    }
26
27
    /**
28
     * @return bool|ExtensionInterface
29
     */
30
    public function getContainerExtension()
31
    {
32
        if (null === $this->extension) {
33
            $class = $this->getContainerExtensionClass();
34
35
            if (class_exists($class)) {
36
                $extension = new $class();
37
38
                if (!$extension instanceof ExtensionInterface) {
39
                    throw new \LogicException(sprintf('Extension %s must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface.', $class));
40
                }
41
                $this->extension = $extension;
42
            } else {
43
                $this->extension = false;
44
            }
45
        }
46
        if ($this->extension) {
47
            return $this->extension;
48
        }
49
    }
50
}
51