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
|
|
|
$parameterRefBuilderDefinition = $container->getDefinition('swagger.document.parameter_ref_builder'); |
48
|
|
|
$publicDocsConfig = $config['document']['public']; |
49
|
|
|
$arguments = [$publicDocsConfig['base_url'], $publicDocsConfig['scheme'], $publicDocsConfig['host']]; |
50
|
|
|
$parameterRefBuilderDefinition->setArguments($arguments); |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
if ($container->hasParameter('test.client.class')) { |
54
|
|
|
$container->setParameter('test.client.class', 'KleijnWeb\SwaggerBundle\Test\ApiTestClient'); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
public function getAlias() |
62
|
|
|
{ |
63
|
|
|
return "swagger"; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|