Completed
Push — master ( e8bfce...313e31 )
by Arnaud
13s queued 11s
created

LAGAdminExtension::load()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 39
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 6.0208

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 6
eloc 25
c 3
b 0
f 0
nc 32
nop 2
dl 0
loc 39
ccs 22
cts 24
cp 0.9167
crap 6.0208
rs 8.8977
1
<?php
2
3
namespace LAG\AdminBundle\DependencyInjection;
4
5
use Symfony\Component\Config\FileLocator;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
8
use Symfony\Component\DependencyInjection\Loader;
9
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
10
11
/**
12
 * Load AdminBundle configuration into the container.
13
 */
14
class LAGAdminExtension extends Extension implements PrependExtensionInterface
15
{
16
    /**
17
     * Load the configuration into the container.
18
     */
19 6
    public function load(array $configs, ContainerBuilder $builder)
20
    {
21 6
        $configuration = new Configuration();
22 6
        $config = $this->processConfiguration($configuration, $configs);
23
24 6
        $loader = new Loader\YamlFileLoader($builder, new FileLocator(__DIR__.'/../Resources/config'));
25 6
        $loader->load('services.yaml');
26
27 6
        if ('dev' === $builder->getParameter('kernel.environment')) {
28
            $loader->load('services_dev.yaml');
29
        }
30 6
        $adminsConfig = [];
31 6
        $enableExtraConfig = true;
32
33 6
        if (!key_exists('application', $config)) {
34 4
            $config['application'] = [
35
                'enable_menus' => true,
36
                'resources_path' => null,
37
            ];
38
        }
39
40 6
        if (key_exists('enable_extra_configuration', $config['application'])) {
41 2
            $enableExtraConfig = $config['application']['enable_extra_configuration'];
42
        }
43 6
        $applicationConfig = $config['application'];
44
45 6
        if (key_exists('admins', $config)) {
46 6
            $adminsConfig = $config['admins'];
47
        }
48
49 6
        if (!key_exists('menus', $config)) {
50
            $config['menus'] = [];
51
        }
52 6
        $builder->setParameter('lag.admin.enable_extra_configuration', $enableExtraConfig);
53 6
        $builder->setParameter('lag.admin.application_configuration', $applicationConfig);
54 6
        $builder->setParameter('lag.admins', $adminsConfig);
55 6
        $builder->setParameter('lag.menus', $config['menus']);
56 6
        $builder->setParameter('lag.enable_menus', $config['application']['enable_menus']);
57 6
        $builder->setParameter('lag.admin.resources_path', $config['application']['resources_path']);
58 6
    }
59
60
    /**
61
     * @return string
62
     */
63 2
    public function getAlias()
64
    {
65 2
        return 'lag_admin';
66
    }
67
68 2
    public function prepend(ContainerBuilder $container)
69
    {
70 2
        $container->prependExtensionConfig('knp_menu', [
71 1
            'twig' => [
72 1
                'template' => '@LAGAdmin/Menu/menu-base.html.twig',
73
            ],
74
        ]);
75 2
    }
76
}
77