SWPBridgeExtension   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 5
dl 0
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B load() 0 29 8
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
    public function load(array $configs, ContainerBuilder $container)
34
    {
35
        $defaultOptions = [];
36
        $configuration = new Configuration();
37
        $config = $this->processConfiguration($configuration, $configs);
38
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
39
        $loader->load('services.yml');
40
        $loader->load('validators.yml');
41
        $loader->load('transformers.yml');
42
43
        $mainKeys = ['api', 'auth'];
44
        foreach ($mainKeys as $mainKey) {
45
            if (isset($config[$mainKey])) {
46
                foreach ($config[$mainKey] as $key => $value) {
47
                    if (!empty($value)) {
48
                        $container->setParameter(sprintf('%s.%s.%s', $this->getAlias(), $mainKey, $key), $value);
49
                    }
50
                }
51
            }
52
        }
53
54
        if (isset($config['options']) && is_array($config['options'])) {
55
            $defaultOptions = $config['options'];
56
        }
57
        $container->setParameter($this->getAlias().'.options', $defaultOptions);
58
        if ($config['persistence']['orm']['enabled']) {
59
            $this->registerStorage(Drivers::DRIVER_DOCTRINE_ORM, $config['persistence']['orm']['classes'], $container);
60
        }
61
    }
62
}
63