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\HttpKernel\DependencyInjection\Extension; |
9
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* This is the class that loads and manages your bundle configuration. |
13
|
|
|
* |
14
|
|
|
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html |
15
|
|
|
*/ |
16
|
|
|
class MediaMonksRestApiExtension extends Extension implements ExtensionInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* {@inheritdoc} |
20
|
|
|
*/ |
21
|
3 |
|
public function load(array $configs, ContainerBuilder $container) |
22
|
|
|
{ |
23
|
3 |
|
$config = $this->processConfiguration(new Configuration(), $configs); |
24
|
|
|
|
25
|
3 |
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
26
|
3 |
|
$loader->load('services.xml'); |
27
|
|
|
|
28
|
3 |
|
$container->getDefinition('mediamonks_rest_api.request_matcher') |
29
|
3 |
|
->replaceArgument(0, $config['request_matcher']['whitelist']); |
30
|
3 |
|
$container->getDefinition('mediamonks_rest_api.request_matcher') |
31
|
3 |
|
->replaceArgument(1, $config['request_matcher']['blacklist']); |
32
|
|
|
|
33
|
3 |
|
$container->getDefinition('mediamonks_rest_api.request_transformer') |
34
|
3 |
|
->replaceArgument(0, $config['output_formats']); |
35
|
|
|
|
36
|
3 |
|
$container->getDefinition('mediamonks_rest_api.response_transformer') |
37
|
3 |
|
->replaceArgument(2, [ |
38
|
3 |
|
'debug' => $this->getDebug($config, $container), |
39
|
3 |
|
'post_message_origin' => $config['post_message_origin'] |
40
|
3 |
|
]); |
41
|
3 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return string |
45
|
|
|
*/ |
46
|
3 |
|
public function getAlias() |
47
|
|
|
{ |
48
|
3 |
|
return 'mediamonks_rest_api'; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param array $config |
53
|
|
|
* @param ContainerBuilder $container |
54
|
|
|
* @return bool |
55
|
|
|
*/ |
56
|
3 |
|
public function getDebug(array $config, ContainerBuilder $container) |
57
|
|
|
{ |
58
|
3 |
|
if (isset($config['debug'])) { |
59
|
|
|
return $config['debug']; |
60
|
|
|
} |
61
|
3 |
|
if ($container->hasParameter('kernel.debug')) { |
62
|
1 |
|
return $container->getParameter('kernel.debug'); |
63
|
|
|
} |
64
|
2 |
|
return false; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|