Completed
Push — master ( 9ec196...c21c38 )
by Alex
11:51
created

OrbitaleCmsExtension::isSymfony3()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
* This file is part of the OrbitaleCmsBundle package.
5
*
6
* (c) Alexandre Rock Ancelet <[email protected]>
7
*
8
* For the full copyright and license information, please view the LICENSE
9
* file that was distributed with this source code.
10
*/
11
12
namespace Orbitale\Bundle\CmsBundle\DependencyInjection;
13
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\Config\FileLocator;
16
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
17
use Symfony\Component\DependencyInjection\Loader;
18
use Symfony\Component\HttpKernel\Kernel;
19
20
/**
21
 * This is the class that loads and manages your bundle configuration.
22
 *
23
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
24
 */
25
class OrbitaleCmsExtension extends Extension
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function load(array $configs, ContainerBuilder $container)
31
    {
32
        $configuration = new Configuration();
33
        $config = $this->processConfiguration($configuration, $configs);
34
35
        foreach ($config['layouts'] as $name => $layout) {
36
            $config['layouts'][$name] = array_merge(array(
37
                'name' => $name,
38
                'assets_css' => '',
39
                'assets_js' => '',
40
                'host' => '',
41
                'pattern' => '',
42
            ), $layout);
43
            if (!$config['layouts'][$name]['host'] && !$config['layouts'][$name]['pattern']) {
44
                // If the user does not specify anything in the host nor the pattern,
45
                //  we force the pattern to match at least the root, else the layout would never be used...
46
                $config['layouts'][$name]['pattern'] = '^/';
47
            }
48
        }
49
50
        // Sort configs by host, because host is checked before pattern.
51
        uasort($config['layouts'], function ($a, $b) {
52
            if ($a['host'] && $b['host']) {
53
                return strcasecmp($a['host'], $b['host']);
54
            } elseif ($a['host'] && !$b['host']) {
55
                return -1;
56
            } else {
57
                return 1;
58
            }
59
        });
60
61
        $container->setParameter('orbitale_cms.config', $config);
62
63
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
64
        $loader->load('services.yml');
65
        if ($this->isSymfony3()) {
66
            $loader->load('services_v3.yml');
67
        } else {
68
            $loader->load('services_v2.yml');
69
        }
70
    }
71
72
    /**
73
     * @return bool
74
     */
75
    protected function isSymfony3()
76
    {
77
        return 3 === Kernel::MAJOR_VERSION;
78
    }
79
}
80