1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MediaMonks\RestApiBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; |
8
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
9
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
10
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* This is the class that loads and manages your bundle configuration. |
14
|
|
|
* |
15
|
|
|
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html |
16
|
|
|
*/ |
17
|
|
|
class MediaMonksRestApiExtension extends Extension implements ExtensionInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
3 |
|
public function load(array $configs, ContainerBuilder $container) |
23
|
|
|
{ |
24
|
3 |
|
$config = $this->processConfiguration(new Configuration(), $configs); |
25
|
|
|
|
26
|
3 |
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
27
|
3 |
|
$loader->load('services.xml'); |
28
|
|
|
|
29
|
3 |
|
$container->getDefinition('mediamonks_rest_api.request_matcher') |
30
|
3 |
|
->replaceArgument(0, $config['request_matcher']['whitelist']); |
31
|
3 |
|
$container->getDefinition('mediamonks_rest_api.request_matcher') |
32
|
3 |
|
->replaceArgument(1, $config['request_matcher']['blacklist']); |
33
|
|
|
|
34
|
3 |
|
$container->getDefinition('mediamonks_rest_api.response_transformer') |
35
|
3 |
|
->replaceArgument( |
36
|
3 |
|
1, |
37
|
|
|
[ |
38
|
3 |
|
'debug' => $this->getDebug($config, $container), |
39
|
3 |
|
'post_message_origin' => $config['post_message_origin'], |
40
|
|
|
] |
41
|
3 |
|
); |
42
|
|
|
|
43
|
3 |
|
$this->loadSerializer($container, $config); |
44
|
3 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param ContainerBuilder $container |
48
|
|
|
* @param array $config |
49
|
|
|
*/ |
50
|
3 |
|
protected function loadSerializer(ContainerBuilder $container, array $config) |
51
|
|
|
{ |
52
|
3 |
|
if (!$container->has($config['serializer'])) { |
53
|
3 |
|
$config['serializer'] = 'mediamonks_rest_api.serializer.'.$config['serializer']; |
54
|
3 |
|
} |
55
|
|
|
|
56
|
3 |
|
$container->getDefinition('mediamonks_rest_api.request_transformer') |
57
|
3 |
|
->replaceArgument(0, new Reference($config['serializer'])) |
58
|
|
|
; |
59
|
3 |
|
$container->getDefinition('mediamonks_rest_api.response_transformer') |
60
|
3 |
|
->replaceArgument(0, new Reference($config['serializer'])) |
61
|
|
|
; |
62
|
3 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
3 |
|
public function getAlias() |
68
|
|
|
{ |
69
|
3 |
|
return 'mediamonks_rest_api'; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param array $config |
74
|
|
|
* @param ContainerBuilder $container |
75
|
|
|
* @return bool |
76
|
|
|
*/ |
77
|
3 |
|
public function getDebug(array $config, ContainerBuilder $container) |
78
|
|
|
{ |
79
|
3 |
|
if (isset($config['debug'])) { |
80
|
|
|
return $config['debug']; |
81
|
|
|
} |
82
|
3 |
|
if ($container->hasParameter('kernel.debug')) { |
83
|
1 |
|
return $container->getParameter('kernel.debug'); |
84
|
|
|
} |
85
|
|
|
|
86
|
2 |
|
return false; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|