/
KernelExtension.php
125 lines (108 loc) · 4.13 KB
/
KernelExtension.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
namespace Symfony\Framework\DependencyInjection;
use Symfony\Components\DependencyInjection\Extension\Extension;
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Components\DependencyInjection\ContainerBuilder;
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* KernelExtension.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.org>
*/
class KernelExtension extends Extension
{
/**
* Loads the test configuration.
*
* @param array $config A configuration array
* @param ContainerBuilder $container A ContainerBuilder instance
*/
public function testLoad($config, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
$loader->load('test.xml');
}
/**
* Loads the session configuration.
*
* @param array $config A configuration array
* @param ContainerBuilder $container A ContainerBuilder instance
*/
public function sessionLoad($config, ContainerBuilder $container)
{
if (!$container->hasDefinition('session')) {
$loader = new XmlFileLoader($container, array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
$loader->load('session.xml');
}
if (isset($config['default_locale'])) {
$container->setParameter('session.default_locale', $config['default_locale']);
}
if (isset($config['class'])) {
$container->setParameter('session.class', $config['class']);
}
foreach (array('name', 'lifetime', 'path', 'domain', 'secure', 'httponly', 'cache_limiter', 'pdo.db_table') as $name) {
if (isset($config['session'][$name])) {
$container->setParameter('session.options.'.$name, $config['session'][$name]);
}
}
if (isset($config['session']['class'])) {
$class = $config['session']['class'];
if (in_array($class, array('Native', 'Pdo'))) {
$class = 'Symfony\\Components\\HttpFoundation\\SessionStorage\\'.$class.'SessionStorage';
}
$container->setParameter('session.session', 'session.session.'.strtolower($class));
}
}
/**
* Loads the config configuration.
*
* @param array $config A configuration array
* @param ContainerBuilder $container A ContainerBuilder instance
*/
public function configLoad($config, ContainerBuilder $container)
{
if (!$container->hasDefinition('event_dispatcher')) {
$loader = new XmlFileLoader($container, array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config'));
$loader->load('services.xml');
if ($container->getParameter('kernel.debug')) {
$loader->load('debug.xml');
$container->setDefinition('event_dispatcher', $container->findDefinition('debug.event_dispatcher'));
}
}
if (isset($config['charset'])) {
$container->setParameter('kernel.charset', $config['charset']);
}
if (array_key_exists('error_handler', $config)) {
if (false === $config['error_handler']) {
$container->getDefinition('error_handler')->setMethodCalls(array());
} else {
$container->getDefinition('error_handler')->addMethodCall('register', array());
$container->setParameter('error_handler.level', $config['error_handler']);
}
}
}
/**
* Returns the base path for the XSD files.
*
* @return string The XSD base path
*/
public function getXsdValidationBasePath()
{
return false;
}
public function getNamespace()
{
return 'http://www.symfony-project.org/schema/dic/symfony/kernel';
}
public function getAlias()
{
return 'kernel';
}
}