Completed
Push — master ( d87ed8...99bf40 )
by Artem
10s
created

FreshCommonApiExtension::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 2
eloc 11
nc 2
nop 2
1
<?php
2
/**
3
 * This file is part of the FreshCommonApiBundle
4
 *
5
 * (c) Artem Genvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Fresh\CommonApiBundle\DependencyInjection;
12
13
use Fresh\CommonApiBundle\EventListener\JsonDecoderListener;
14
use Symfony\Component\Config\FileLocator;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Definition;
17
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
18
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
19
20
/**
21
 * This is the class that loads and manages FreshCommonApiBundle configuration.
22
 *
23
 * @author Artem Genvald <[email protected]>
24
 */
25
class FreshCommonApiExtension extends Extension
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function load(array $configs, ContainerBuilder $container)
31
    {
32
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
33
        $loader->load('services.yml');
34
35
        $configuration = new Configuration();
36
        $config = $this->processConfiguration($configuration, $configs);
37
38
        if (true === $config['enable_json_decoder']) {
39
            $definition = new Definition(JsonDecoderListener::class);
40
            $definition->addTag('kernel.event_listener', [
41
                'event'  => 'kernel.request',
42
                'method' => 'onKernelRequest',
43
            ]);
44
            $container->setDefinition('fresh_common_api.listener.json_decoder', $definition);
45
        }
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getAlias()
52
    {
53
        return 'fresh_common_api';
54
    }
55
}
56