Completed
Push — dev ( 33641b...44dc2b )
by Matej
05:52
created

VelikonjaLabbyExtension::prepend()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4.0092

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 17
ccs 11
cts 12
cp 0.9167
rs 9.2
cc 4
eloc 9
nc 4
nop 1
crap 4.0092
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 2
        if (isset($bundles['DoctrineBundle'])) {
52 2
            $doctrineConfig = $container->getExtensionConfig('doctrine');
53
54
            // find first doctrine dbal config and append it to labby config
55 2
            $length = count($doctrineConfig);
56 2
            for ($i = 0; $i < $length; $i++) {
57 2
                if (isset($doctrineConfig[$i]['dbal'])) {
58 2
                    $container->prependExtensionConfig('velikonja_labby', array('db' => $doctrineConfig[$i]['dbal']));
59 2
                    break;
60
                }
61
            }
62 2
        }
63 2
    }
64
}
65