Completed
Push — master ( bb050e...36e41a )
by Paweł
11:10
created

SWPBridgeExtension::load()   B

Complexity

Conditions 8
Paths 20

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 8.216

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 17
cts 20
cp 0.85
rs 8.2114
c 0
b 0
f 0
cc 8
nc 20
nop 2
crap 8.216
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Bridge Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\BridgeBundle\DependencyInjection;
16
17
use SWP\Bundle\StorageBundle\Drivers;
18
use SWP\Bundle\StorageBundle\DependencyInjection\Extension\Extension;
19
use Symfony\Component\Config\FileLocator;
20
use Symfony\Component\DependencyInjection\ContainerBuilder;
21
use Symfony\Component\DependencyInjection\Loader;
22
23
/**
24
 * This is the class that loads and manages your bundle configuration.
25
 *
26
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
27
 */
28
class SWPBridgeExtension extends Extension
29
{
30
    /**
31
     * {@inheritdoc}
32
     */
33 1
    public function load(array $configs, ContainerBuilder $container)
34
    {
35 1
        $defaultOptions = [];
36 1
        $configuration = new Configuration();
37 1
        $config = $this->processConfiguration($configuration, $configs);
38 1
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
39 1
        $loader->load('services.yml');
40 1
        $loader->load('validators.yml');
41 1
        $loader->load('transformers.yml');
42
43 1
        $mainKeys = ['api', 'auth'];
44 1
        foreach ($mainKeys as $mainKey) {
45 1
            if (isset($config[$mainKey])) {
46
                foreach ($config[$mainKey] as $key => $value) {
47
                    if (!empty($value)) {
48 1
                        $container->setParameter(sprintf('%s.%s.%s', $this->getAlias(), $mainKey, $key), $value);
49
                    }
50
                }
51
            }
52
        }
53
54 1
        if (isset($config['options']) && is_array($config['options'])) {
55
            $defaultOptions = $config['options'];
56
        }
57 1
        $container->setParameter($this->getAlias().'.options', $defaultOptions);
58 1
        if ($config['persistence']['orm']['enabled']) {
59 1
            $this->registerStorage(Drivers::DRIVER_DOCTRINE_ORM, $config['persistence']['orm']['classes'], $container);
60
        }
61 1
    }
62
}
63