1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the FreshCommonApiBundle |
4
|
|
|
* |
5
|
|
|
* (c) Artem Genvald <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Fresh\CommonApiBundle\DependencyInjection; |
12
|
|
|
|
13
|
|
|
use Fresh\CommonApiBundle\EventListener\JsonDecoderListener; |
14
|
|
|
use Symfony\Component\Config\FileLocator; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
17
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
18
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* This is the class that loads and manages FreshCommonApiBundle configuration. |
22
|
|
|
* |
23
|
|
|
* @author Artem Genvald <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class FreshCommonApiExtension extends Extension |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
|
|
public function load(array $configs, ContainerBuilder $container) |
31
|
|
|
{ |
32
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
33
|
|
|
$loader->load('services.yml'); |
34
|
|
|
|
35
|
|
|
$configuration = new Configuration(); |
36
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
37
|
|
|
|
38
|
|
|
if (true === $config['enable_json_decoder']) { |
39
|
|
|
$definition = new Definition(JsonDecoderListener::class); |
40
|
|
|
$definition->addTag('kernel.event_listener', [ |
41
|
|
|
'event' => 'kernel.request', |
42
|
|
|
'method' => 'onKernelRequest', |
43
|
|
|
]); |
44
|
|
|
$container->setDefinition('fresh_common_api.listener.json_decoder', $definition); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
|
public function getAlias() |
52
|
|
|
{ |
53
|
|
|
return 'fresh_common_api'; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|