From ceaf69b32e7107af250c89b0085958e21f7e4a37 Mon Sep 17 00:00:00 2001 From: Drak Date: Sat, 6 Apr 2013 17:24:31 +0100 Subject: [PATCH] [FrameworkBundle] Use more sophisticated validation and configuration. --- .../DependencyInjection/Configuration.php | 13 +++++++++---- .../DependencyInjection/FrameworkExtension.php | 14 +++++++++++++- .../Resources/config/schema/symfony-1.0.xsd | 1 + .../DependencyInjection/Fixtures/php/full.php | 2 +- .../DependencyInjection/Fixtures/xml/full.xml | 2 +- .../DependencyInjection/Fixtures/yml/full.yml | 2 +- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index b714af0a26..ffd05e426f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -184,10 +184,15 @@ class Configuration implements ConfigurationInterface ->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() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 8440c4777f..368b591b5e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -18,6 +18,7 @@ use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; 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; @@ -318,7 +319,18 @@ class FrameworkExtension extends Extension $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']); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd index d843151c83..982991c17b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd @@ -79,6 +79,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php index e3596df71f..37afa04dd2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -24,7 +24,7 @@ $container->loadFromExtension('framework', array( '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' => '/', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index 386c7105fb..17eb5462a5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -12,7 +12,7 @@ - + loader.foo loader.bar diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml index 6fb534be76..4bffc8645a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -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: /