NetgenOpenWeatherMapExtension::load()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 2
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
1
<?php
2
3
namespace Netgen\Bundle\OpenWeatherMapBundle\DependencyInjection;
4
5
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ConfigurationProcessor;
6
use Symfony\Component\Config\FileLocator;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Loader;
9
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
10
11
class NetgenOpenWeatherMapExtension extends Extension
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function load(array $configs, ContainerBuilder $container)
17
    {
18
        $configuration = new Configuration();
19
        $config = $this->processConfiguration($configuration, $configs);
20
21
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
22
        $loader->load('services.yml');
23
24
        $processor = new ConfigurationProcessor($container, 'netgen_open_weather_map');
25
        $configArrays = array('api_settings', 'cache_settings');
26
27
        $scopes = array_merge(array('default'), $container->getParameter('ezpublish.siteaccess.list'));
28
29
        foreach ($configArrays as $configArray) {
30
            $processor->mapConfigArray($configArray, $config);
31
32
            foreach ($scopes as $scope) {
33
                $scopeConfig = $container->getParameter('netgen_open_weather_map.' . $scope . '.' . $configArray);
34
                foreach ($scopeConfig as $key => $value) {
35
                    $container->setParameter(
36
                        'netgen_open_weather_map.' . $scope . '.' . $configArray . '.' . $key,
37
                        $value
38
                    );
39
                }
40
            }
41
        }
42
    }
43
}
44