Completed
Pull Request — master (#154)
by Arnaud
03:37
created

LAGAdminExtension   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 30
c 3
b 0
f 0
dl 0
loc 59
ccs 20
cts 25
cp 0.8
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A prepend() 0 5 1
A getAlias() 0 3 1
B load() 0 39 6
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 6
     */
19
    public function load(array $configs, ContainerBuilder $builder)
20 6
    {
21 6
        $configuration = new Configuration();
22
        $config = $this->processConfiguration($configuration, $configs);
23 6
24 6
        $loader = new Loader\YamlFileLoader($builder, new FileLocator(__DIR__.'/../Resources/config'));
25
        $loader->load('services.yaml');
26 6
27
        if ('dev' === $builder->getParameter('kernel.environment')) {
28
            $loader->load('services_dev.yaml');
29 6
        }
30 6
        $adminsConfig = [];
31 6
        $enableExtraConfig = true;
32
33 6
        if (!key_exists('application', $config)) {
34
            $config['application'] = [
35
                'enable_menus' => true,
36
                'resources_path' => null,
37
            ];
38
        }
39
40 6
        if (key_exists('enable_extra_configuration', $config['application'])) {
41 6
            $enableExtraConfig = $config['application']['enable_extra_configuration'];
42
        }
43
        $applicationConfig = $config['application'];
44 6
45
        if (key_exists('admins', $config)) {
46
            $adminsConfig = $config['admins'];
47 6
        }
48 6
49 6
        if (!key_exists('menus', $config)) {
50 6
            $config['menus'] = [];
51 6
        }
52
        $builder->setParameter('lag.admin.enable_extra_configuration', $enableExtraConfig);
53
        $builder->setParameter('lag.admin.application_configuration', $applicationConfig);
54
        $builder->setParameter('lag.admins', $adminsConfig);
55
        $builder->setParameter('lag.menus', $config['menus']);
56 2
        $builder->setParameter('lag.enable_menus', $config['application']['enable_menus']);
57
        $builder->setParameter('lag.admin.resources_path', $config['application']['resources_path']);
58 2
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getAlias()
64
    {
65
        return 'lag_admin';
66
    }
67
68
    public function prepend(ContainerBuilder $container)
69
    {
70
        $container->prependExtensionConfig('knp_menu', [
71
            'twig' => [
72
                'template' => '@LAGAdmin/Menu/menu-base.html.twig',
73
            ],
74
        ]);
75
    }
76
}
77