Completed
Push — master ( 387f81...310708 )
by Benjamin
02:49
created

AlpixelMenuExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 5
Bugs 0 Features 2
Metric Value
wmc 4
c 5
b 0
f 2
lcom 0
cbo 7
dl 0
loc 31
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 15 2
A prepend() 0 9 2
1
<?php
2
3
namespace Alpixel\Bundle\MenuBundle\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
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;
11
12
/**
13
 * This is the class that loads and manages your bundle configuration.
14
 *
15
 * @link http://symfony.com/doc/current/cookbook/bundles/extension.html
16
 */
17
class AlpixelMenuExtension extends Extension implements PrependExtensionInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function load(array $configs, ContainerBuilder $container)
23
    {
24
        if (!$container->hasParameter('default_locale')) {
25
            throw new UndefinedOptionsException('The default locale parameter must be defined under parameters in your symfony configuration');
26
        }
27
28
        $configuration = new Configuration();
29
        $this->processConfiguration($configuration, $configs);
30
31
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
32
        $loader->load('services.yml');
33
34
        $menuBuilder = $container->getDefinition('alpixel_menu.builder');
35
        $menuBuilder->addMethodCall('setDefaultLocale', [$container->getParameter('default_locale')]);
36
    }
37
38
    public function prepend(ContainerBuilder $container)
39
    {
40
        $parser = new Parser();
41
        $config = $parser->parse(file_get_contents(__DIR__ . '/../Resources/config/config.yml'));
42
43
        foreach ($config as $key => $configuration) {
44
            $container->prependExtensionConfig($key, $configuration);
45
        }
46
    }
47
}
48