LeogoutSeoExtension::loadIfConfigured()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 4
1
<?php
2
3
namespace Leogout\Bundle\SeoBundle\DependencyInjection;
4
5
use Symfony\Component\Config\FileLocator;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
8
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
9
10
/**
11
 * Description of LeogoutSeoExtension.
12
 *
13
 * @author: leogout
14
 */
15
class LeogoutSeoExtension extends Extension
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function load(array $configs, ContainerBuilder $container)
21
    {
22
        $configuration = new Configuration();
23
        $config = $this->processConfiguration($configuration, $configs);
24
25
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
26
27
        $this->loadIfConfigured('basic', $container, $loader, $config);
28
        $this->loadIfConfigured('og', $container, $loader, $config);
29
        $this->loadIfConfigured('twitter', $container, $loader, $config);
30
31
        $loader->load('services.xml');
32
    }
33
34
    /**
35
     * Checks if the configuration with this name isn't empty.
36
     * Creates a parameter and loads a configuration file of the given configuration name.
37
     *
38
     * @param string $configName
39
     * @param ContainerBuilder $container
40
     * @param XmlFileLoader $loader
41
     * @param array $config
42
     */
43
    private function loadIfConfigured($configName, ContainerBuilder $container, XmlFileLoader $loader, array $config)
44
    {
45
        if (!isset($config[$configName])) {
46
            return;
47
        }
48
        $config = array_merge($config['general'], $config[$configName]);
49
        $container->setParameter(
50
            sprintf('leogout_seo.%s', $configName),
51
            $config
52
        );
53
        $loader->load(sprintf('seo/%s.xml', $configName));
54
    }
55
}
56