Completed
Pull Request — master (#52)
by John
02:48
created

KleijnWebSwaggerExtension::load()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 0 Features 0
Metric Value
c 7
b 0
f 0
dl 0
loc 26
rs 8.5806
cc 4
eloc 16
nc 8
nop 2
1
<?php
2
/*
3
 * This file is part of the KleijnWeb\SwaggerBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\SwaggerBundle\DependencyInjection;
10
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
use Symfony\Component\Config\FileLocator;
13
use Symfony\Component\DependencyInjection\Reference;
14
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
15
use Symfony\Component\DependencyInjection\Loader;
16
17
/**
18
 * @author John Kleijn <[email protected]>
19
 */
20
class KleijnWebSwaggerExtension extends Extension
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function load(array $configs, ContainerBuilder $container)
26
    {
27
        $config = $this->processConfiguration(new Configuration(), $configs);
28
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
29
        $loader->load('services.yml');
30
31
        $container->setParameter('swagger.document.base_path', $config['document']['base_path']);
32
        $container->setParameter('swagger.serializer.namespace', $config['serializer']['namespace']);
33
34
        $serializerType = $config['serializer']['type'];
35
        $container->setAlias('swagger.serializer.target', 'swagger.serializer.' . $serializerType);
36
37
        if ($serializerType !== 'array') {
38
            $resolverDefinition = $container->getDefinition('swagger.request.processor.content_decoder');
39
            $resolverDefinition->addArgument(new Reference('swagger.serializer.type_resolver'));
40
        }
41
42
        if (isset($config['document']['cache'])) {
43
            $resolverDefinition = $container->getDefinition('swagger.document.repository');
44
            $resolverDefinition->addArgument(new Reference($config['document']['cache']));
45
        }
46
47
        if ($container->hasParameter('test.client.class')) {
48
            $container->setParameter('test.client.class', 'KleijnWeb\SwaggerBundle\Test\ApiTestClient');
49
        }
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getAlias()
56
    {
57
        return "swagger";
58
    }
59
}
60