-
Notifications
You must be signed in to change notification settings - Fork 259
/
FOSJsRoutingExtension.php
70 lines (60 loc) · 2.29 KB
/
FOSJsRoutingExtension.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
* This file is part of the FOSJsRoutingBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\JsRoutingBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Serializer\Serializer;
/**
* FOSJsRoutingExtension
* Load configuration.
*
* @author William DURAND <william.durand1@gmail.com>
*/
class FOSJsRoutingExtension extends Extension
{
/**
* Load configuration.
*/
public function load(array $configs, ContainerBuilder $container)
{
$processor = new Processor();
$configuration = new Configuration();
$config = $processor->processConfiguration($configuration, $configs);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
$loader->load('controllers.xml');
if (isset($config['serializer'])) {
$container->setAlias('fos_js_routing.serializer', new Alias($config['serializer'], false));
} else {
$loader->load('serializer.xml');
}
$container->setAlias(
'fos_js_routing.router',
new Alias($config['router'], false)
);
$container
->getDefinition('fos_js_routing.extractor')
->replaceArgument(1, $config['routes_to_expose']);
if (isset($config['request_context_base_url'])) {
$container->setParameter('fos_js_routing.request_context_base_url', $config['request_context_base_url']);
}
if (isset($config['cache_control'])) {
$config['cache_control']['enabled'] = true;
} else {
$config['cache_control'] = array('enabled' => false);
}
$container->setParameter('fos_js_routing.cache_control', $config['cache_control']);
}
}