Skip to content

Commit be6665d

Browse files
author
Drak
committed
[FrameworkBundle] Use more sophisticated validation and configuration.
1 parent 73ef3c5 commit be6665d

File tree

6 files changed

+26
-8
lines changed

6 files changed

+26
-8
lines changed

DependencyInjection/Configuration.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,15 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
184184
->info('session configuration')
185185
->canBeUnset()
186186
->children()
187-
->booleanNode('auto_start')->info('Flag for SessionListener to start session')
188-
->defaultValue(true)->end()
189-
->scalarNode('on_demand_mode')->info('Start session on demand (on access), 0 - off, 1 - on (strict), 2 - off (lax)')
190-
->defaultValue(1)->end()
187+
->booleanNode('auto_start')
188+
->defaultTrue()
189+
->info('Flag for SessionListener to start session')
190+
->end()
191+
->enumNode('on_demand_mode')
192+
->values(array('off', 'on', 'off_lax'))
193+
->defaultValue('on')
194+
->info('Start session on demand: off, on, or off_lax')
195+
->end()
191196
->scalarNode('mock_name')->defaultValue('MOCKSESSID')->end()
192197
->scalarNode('storage_id')->defaultValue('session.storage.native')->end()
193198
->scalarNode('handler_id')->defaultValue('session.handler.native_file')->end()

DependencyInjection/FrameworkExtension.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Config\Resource\FileResource;
1919
use Symfony\Component\Config\Resource\DirectoryResource;
2020
use Symfony\Component\Finder\Finder;
21+
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
2122
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
2223
use Symfony\Component\Config\FileLocator;
2324

@@ -318,7 +319,18 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
318319
$container->setParameter('session.auto_start', $config['auto_start']);
319320

320321
// this controls the session start on demand feature
321-
$container->setParameter('session.storage.on_demand_mode', $config['on_demand_mode']);
322+
switch ($config['on_demand_mode']) {
323+
// already validated
324+
case 'on':
325+
$demand = SessionStorageInterface::START_ON_DEMAND;
326+
break;
327+
case 'off':
328+
$demand = SessionStorageInterface::NO_START_ON_DEMAND_STRICT;
329+
break;
330+
case 'off_lax':
331+
$demand = SessionStorageInterface::NO_START_ON_DEMAND_LAX;
332+
}
333+
$container->setParameter('session.storage.on_demand_mode', $demand);
322334

323335
$container->setParameter('session.storage.mock_name', $config['mock_name']);
324336

Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<xsd:complexType name="session">
8080
<xsd:attribute name="auto-start" type="xsd:boolean" />
8181
<xsd:attribute name="on-demand-mode" type="xsd:string" />
82+
<xsd:attribute name="mock-name" type="xsd:string" />
8283
<xsd:attribute name="storage-id" type="xsd:string" />
8384
<xsd:attribute name="handler-id" type="xsd:string" />
8485
<xsd:attribute name="name" type="xsd:string" />

Tests/DependencyInjection/Fixtures/php/full.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
'session' => array(
2525
'storage_id' => 'session.storage.native',
2626
'handler_id' => 'session.handler.native_file',
27-
'on_demand_mode' => 1,
27+
'on_demand_mode' => 'on',
2828
'name' => '_SYMFONY',
2929
'cookie_lifetime' => 86400,
3030
'cookie_path' => '/',

Tests/DependencyInjection/Fixtures/xml/full.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<framework:esi enabled="true" />
1313
<framework:profiler only-exceptions="true" enabled="false" />
1414
<framework:router resource="%kernel.root_dir%/config/routing.xml" type="xml" />
15-
<framework:session gc-maxlifetime="90000" gc-probability="1" gc-divisor="108" storage-id="session.storage.native" handler-id="session.handler.native_file" name="_SYMFONY" cookie-lifetime="86400" cookie-path="/" cookie-domain="example.com" cookie-secure="true" cookie-httponly="true" save-path="/path/to/sessions" auto-start="true" on-demand-mode="1" />
15+
<framework:session gc-maxlifetime="90000" gc-probability="1" gc-divisor="108" storage-id="session.storage.native" handler-id="session.handler.native_file" name="_SYMFONY" cookie-lifetime="86400" cookie-path="/" cookie-domain="example.com" cookie-secure="true" cookie-httponly="true" save-path="/path/to/sessions" auto-start="true" on-demand-mode="on" />
1616
<framework:templating assets-version="SomeVersionScheme" cache="/path/to/cache" >
1717
<framework:loader>loader.foo</framework:loader>
1818
<framework:loader>loader.bar</framework:loader>

Tests/DependencyInjection/Fixtures/yml/full.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ framework:
1818
session:
1919
storage_id: session.storage.native
2020
handler_id: session.handler.native_file
21-
on_demand_mode: 1
21+
on_demand_mode: on
2222
name: _SYMFONY
2323
cookie_lifetime: 86400
2424
cookie_path: /

0 commit comments

Comments
 (0)