Passed
Push — master ( f06103...576e75 )
by Gerhard
10:12
created

EnhavoRoutingExtension::prepend()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 6
nop 1
dl 0
loc 11
ccs 0
cts 7
cp 0
crap 20
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Enhavo\Bundle\RoutingBundle\DependencyInjection;
4
5
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\Config\FileLocator;
8
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
9
use Symfony\Component\DependencyInjection\Loader;
10
use Symfony\Component\Yaml\Yaml;
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 EnhavoRoutingExtension extends AbstractResourceExtension implements PrependExtensionInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function load(array $configs, ContainerBuilder $container)
23
    {
24
        $configuration = new Configuration();
25
        $config = $this->processConfiguration($configuration, $configs);
26
        $this->registerResources('enhavo_routing', $config['driver'], $config['resources'], $container);
27
28
        $container->setParameter('enhavo_routing.classes', $config['classes']);
29
30
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
31
        $loader->load('services/cfm.yaml');
32
        $loader->load('services/form.yaml');
33
        $loader->load('services/general.yaml');
34
        $loader->load('services/generator.yaml');
35
        $loader->load('services/metadata.yaml');
36
        $loader->load('services/router.yaml');
37
    }
38
39
    /**
40
     * @inheritDoc
41
     */
42
    public function prepend(ContainerBuilder $container)
43
    {
44
        $configs = Yaml::parse(file_get_contents(__DIR__.'/../Resources/config/app/config.yaml'));
45
46
        if (class_exists('\Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle')) {
47
            $configs = array_merge($configs, Yaml::parse(file_get_contents(__DIR__.'/../Resources/config/app/config-gedmo.yaml')));
48
        }
49
50
        foreach($configs as $name => $config) {
51
            if (is_array($config)) {
52
                $container->prependExtensionConfig($name, $config);
53
            }
54
        }
55
    }
56
}
57