VelikonjaLabbyExtension   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 96.3%

Importance

Changes 13
Bugs 1 Features 2
Metric Value
wmc 6
c 13
b 1
f 2
lcom 0
cbo 5
dl 0
loc 60
ccs 26
cts 27
cp 0.963
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 20 2
B prepend() 0 28 4
1
<?php
2
3
namespace Velikonja\LabbyBundle\DependencyInjection;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\Config\FileLocator;
7
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
8
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
9
use Symfony\Component\DependencyInjection\Loader;
10
11
/**
12
 * This is the class that loads and manages your bundle configuration
13
 *
14
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
15
 */
16
class VelikonjaLabbyExtension extends Extension implements PrependExtensionInterface
17
{
18
    /**
19
     * {@inheritDoc}
20
     */
21 2
    public function load(array $configs, ContainerBuilder $container)
22
    {
23 2
        $configuration = new Configuration();
24 2
        $config        = $this->processConfiguration($configuration, $configs);
25
26 2
        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
27 2
        $loader->load('services.xml');
28
29 2
        $container->setParameter('velikonja_labby.config', $config);
30 2
        $container->setParameter('velikonja_labby.config.db', $config['db']);
31 2
        $container->setParameter('velikonja_labby.config.fs', $config['fs']);
32 2
        $container->setParameter('velikonja_labby.config.event_executors', $config['event_executors']);
33 2
        $container->setParameter('velikonja_labby.config.remote', $config['remote']);
34 2
        $container->setParameter('velikonja_labby.config.roles', $config['roles']);
35 2
        $container->setParameter('velikonja_labby.config.process_timeout', $config['process_timeout']);
36
37 2
        if (! $config['db']['recreate']) {
38
            $container->removeDefinition('velikonja_labby.event.listener.recreate_database');
39
        }
40 2
    }
41
42
    /**
43
     * Allow an extension to prepend the extension configurations.
44
     *
45
     * @param ContainerBuilder $container
46
     */
47 2
    public function prepend(ContainerBuilder $container)
48
    {
49 2
        $bundles = $container->getParameter('kernel.bundles');
50
51
        $allowedKeys = array(
52 2
            'driver',
53
            'dbname',
54
            'host',
55
            'port',
56
            'user',
57
            'password',
58
            'charset',
59
        );
60
61 2
        if (isset($bundles['DoctrineBundle'])) {
62 2
            $doctrineConfig = $container->getExtensionConfig('doctrine');
63
64
            // find first doctrine dbal config and append it to labby config
65 2
            $length = count($doctrineConfig);
66 2
            for ($i = 0; $i < $length; $i++) {
67 2
                if (isset($doctrineConfig[$i]['dbal'])) {
68 2
                    $output = array_intersect_key($doctrineConfig[$i]['dbal'], array_flip($allowedKeys));
69 2
                    $container->prependExtensionConfig('velikonja_labby', array('db' => $output));
70 2
                    break;
71
                }
72
            }
73
        }
74 2
    }
75
}
76