FreshCommonApiExtension   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 6
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A load() 0 18 2
1
<?php
2
/*
3
 * This file is part of the FreshCommonApiBundle
4
 *
5
 * (c) Artem Henvald <[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
declare(strict_types=1);
12
13
namespace Fresh\CommonApiBundle\DependencyInjection;
14
15
use Fresh\CommonApiBundle\EventListener\JsonDecoderListener;
16
use Symfony\Component\Config\FileLocator;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Definition;
19
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
20
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
21
22
/**
23
 * This is the class that loads and manages FreshCommonApiBundle configuration.
24
 *
25
 * @author Artem Henvald <[email protected]>
26
 */
27
class FreshCommonApiExtension extends Extension
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function load(array $configs, ContainerBuilder $container): void
33
    {
34
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
35
        $loader->load('services.yml');
36
37
        $configuration = new Configuration();
38
        $config = $this->processConfiguration($configuration, $configs);
39
40
        if (true === $config['enable_json_decoder']) {
41
            $definition = new Definition(JsonDecoderListener::class);
42
            $definition->addTag('kernel.event_listener', [
43
                'event' => 'kernel.request',
44
                'method' => 'onKernelRequest',
45
            ]);
46
            $definition->setPrivate(true);
47
            $container->setDefinition(JsonDecoderListener::class, $definition);
48
        }
49
    }
50
}
51