ResponsiveImageExtension::load()   B
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 31
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 16
nc 4
nop 2
1
<?php
2
/**
3
 * This file is part of the IrishDan\ResponsiveImageBundle package.
4
 *
5
 * (c) Daniel Byrne <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE file that was distributed with this source
8
 * code.
9
 */
10
11
namespace IrishDan\ResponsiveImageBundle\DependencyInjection;
12
13
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
16
/**
17
 * Class ResponsiveImageExtension
18
 *
19
 * @package IrishDan\ResponsiveImageBundle\DependencyInjection
20
 */
21
class ResponsiveImageExtension extends Extension
22
{
23
    public function load(array $configs, ContainerBuilder $container)
24
    {
25
        $configuration = new Configuration();
26
        $config        = $this->processConfiguration($configuration, $configs);
27
28
        foreach ($configs as $subConfig) {
29
            $config = array_merge($config, $subConfig);
30
        }
31
32
        // Set as parameter for easier passing.
33
        $container->setParameter('responsive_image', $config);
34
35
        // Create the image directories as parameters for routing.
36
        $container->setParameter('responsive_image.image_directory', $config['image_directory']);
37
        $container->setParameter('responsive_image.image_styles_directory', $config['image_styles_directory']);
38
39
        // Create the image_entity_class parameter.
40
        if (!empty($config['image_entity_class'])) {
41
            $container->setParameter('responsive_image.entity_class', $config['image_entity_class']);
42
        }
43
        else {
44
            $container->setParameter('responsive_image.entity_class', '');
45
        }
46
47
        // Add the cropfocus.html.twig to form resources
48
        $resources = $container->getParameter('twig.form.resources');
49
        $container->setParameter(
50
            'twig.form.resources',
51
            array_merge(['ResponsiveImageBundle::cropfocus.html.twig'], $resources)
52
        );
53
    }
54
}