InnmindRestExtension::load()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 2

Importance

Changes 6
Bugs 1 Features 4
Metric Value
c 6
b 1
f 4
dl 0
loc 29
ccs 24
cts 24
cp 1
rs 8.8571
cc 2
eloc 19
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Innmind\RestBundle\DependencyInjection;
4
5
use Innmind\RestBundle\EventListener\RoutingListener;
6
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Loader;
9
use Symfony\Component\DependencyInjection\Definition;
10
use Symfony\Component\Config\FileLocator;
11
12
class InnmindRestExtension extends Extension
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17 24
    public function load(array $configs, ContainerBuilder $container)
18
    {
19 24
        $configuration = new Configuration;
20 24
        $config = $this->processConfiguration($configuration, $configs);
21 24
        $loader = new Loader\YamlFileLoader(
22 24
            $container,
23 24
            new FileLocator(__DIR__ . '/../Resources/config')
24 24
        );
25 24
        $loader->load('services.yml');
26
27 24
        $registry = $container->getDefinition('innmind_rest.server.registry');
28 24
        $registry->addMethodCall(
29 24
            'load',
30 24
            [['collections' => $config['server']['collections']]]
31 24
        );
32
33 24
        if ($config['server']['prefix'] !== null) {
34 2
            $definition = new Definition(
35 2
                RoutingListener::class,
36 2
                [$config['server']['prefix']]
37 2
            );
38 2
            $definition->addTag('kernel.event_subscriber');
39
40 2
            $container->setDefinition(
41 2
                'innmind_rest.server.listener.route',
42
                $definition
43 2
            );
44 2
        }
45 24
    }
46
}
47