Skip to content

Commit

Permalink
[FrameworkBundle] Use more sophisticated validation and configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Drak committed Apr 6, 2013
1 parent af0a140 commit ceaf69b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
Expand Up @@ -184,10 +184,15 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
->info('session configuration')
->canBeUnset()
->children()
->booleanNode('auto_start')->info('Flag for SessionListener to start session')
->defaultValue(true)->end()
->scalarNode('on_demand_mode')->info('Start session on demand (on access), 0 - off, 1 - on (strict), 2 - off (lax)')
->defaultValue(1)->end()
->booleanNode('auto_start')
->defaultTrue()
->info('Flag for SessionListener to start session')
->end()
->enumNode('on_demand_mode')
->values(array('off', 'on', 'off_lax'))
->defaultValue('on')
->info('Start session on demand: off, on, or off_lax')
->end()
->scalarNode('mock_name')->defaultValue('MOCKSESSID')->end()
->scalarNode('storage_id')->defaultValue('session.storage.native')->end()
->scalarNode('handler_id')->defaultValue('session.handler.native_file')->end()
Expand Down
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\Resource\DirectoryResource;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;

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

// this controls the session start on demand feature
$container->setParameter('session.storage.on_demand_mode', $config['on_demand_mode']);
switch ($config['on_demand_mode']) {
// already validated
case 'on':
$demand = SessionStorageInterface::START_ON_DEMAND;
break;
case 'off':
$demand = SessionStorageInterface::NO_START_ON_DEMAND_STRICT;
break;
case 'off_lax':
$demand = SessionStorageInterface::NO_START_ON_DEMAND_LAX;
}
$container->setParameter('session.storage.on_demand_mode', $demand);

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

Expand Down
Expand Up @@ -79,6 +79,7 @@
<xsd:complexType name="session">
<xsd:attribute name="auto-start" type="xsd:boolean" />
<xsd:attribute name="on-demand-mode" type="xsd:string" />
<xsd:attribute name="mock-name" type="xsd:string" />
<xsd:attribute name="storage-id" type="xsd:string" />
<xsd:attribute name="handler-id" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
Expand Down
Expand Up @@ -24,7 +24,7 @@
'session' => array(
'storage_id' => 'session.storage.native',
'handler_id' => 'session.handler.native_file',
'on_demand_mode' => 1,
'on_demand_mode' => 'on',
'name' => '_SYMFONY',
'cookie_lifetime' => 86400,
'cookie_path' => '/',
Expand Down
Expand Up @@ -12,7 +12,7 @@
<framework:esi enabled="true" />
<framework:profiler only-exceptions="true" enabled="false" />
<framework:router resource="%kernel.root_dir%/config/routing.xml" type="xml" />
<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" />
<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" />
<framework:templating assets-version="SomeVersionScheme" cache="/path/to/cache" >
<framework:loader>loader.foo</framework:loader>
<framework:loader>loader.bar</framework:loader>
Expand Down
Expand Up @@ -18,7 +18,7 @@ framework:
session:
storage_id: session.storage.native
handler_id: session.handler.native_file
on_demand_mode: 1
on_demand_mode: on
name: _SYMFONY
cookie_lifetime: 86400
cookie_path: /
Expand Down

0 comments on commit ceaf69b

Please sign in to comment.