From eaf3f75b31e6665285fa70da530168a09362d881 Mon Sep 17 00:00:00 2001 From: Drak Date: Sat, 20 Apr 2013 19:24:45 +0100 Subject: [PATCH 1/3] Revert "Revert "merged branch drak/start_on_demand (PR #7576)"" This reverts commit 5a3428dc7818195bf907639e26a4cf45340830b8. --- .../Bundle/FrameworkBundle/CHANGELOG.md | 2 ++ .../DependencyInjection/Configuration.php | 10 ++++++ .../FrameworkExtension.php | 9 ++++++ .../EventListener/SessionListener.php | 10 ++++-- .../Resources/config/schema/symfony-1.0.xsd | 3 ++ .../Resources/config/session.xml | 8 +++++ .../DependencyInjection/Fixtures/php/full.php | 2 ++ .../DependencyInjection/Fixtures/xml/full.xml | 2 +- .../DependencyInjection/Fixtures/yml/full.yml | 2 ++ .../FrameworkExtensionTest.php | 3 ++ .../Component/HttpFoundation/CHANGELOG.md | 1 + .../HttpFoundation/Session/Session.php | 2 +- .../Session/SessionBagInterface.php | 2 +- .../Session/SessionInterface.php | 16 +++++----- .../Handler/MemcacheSessionHandler.php | 2 +- .../Handler/MemcachedSessionHandler.php | 2 +- .../Storage/Handler/MongoDbSessionHandler.php | 4 +-- .../Handler/NativeFileSessionHandler.php | 6 ++-- .../Storage/Handler/PdoSessionHandler.php | 14 ++++---- .../Session/Storage/MetadataBag.php | 4 +-- .../Storage/MockArraySessionStorage.php | 17 +++++++--- .../Storage/MockFileSessionStorage.php | 18 ++++------- .../Session/Storage/NativeSessionStorage.php | 31 ++++++++++++------ .../Session/Storage/Proxy/AbstractProxy.php | 10 +++--- .../Session/Storage/Proxy/NativeProxy.php | 2 +- .../Storage/SessionStorageInterface.php | 32 ++++++++++++++----- .../Storage/MockArraySessionStorageTest.php | 30 ++++++++++++++++- .../Storage/MockFileSessionStorageTest.php | 32 +++++++++++++++++-- .../Storage/NativeSessionStorageTest.php | 29 +++++++++++++++++ 29 files changed, 235 insertions(+), 70 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 48dd3ee5e8ead..a72c724bcd5af 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -13,6 +13,8 @@ CHANGELOG * added support for default templates per render tag * added FormHelper::form(), FormHelper::start() and FormHelper::end() * deprecated FormHelper::enctype() in favor of FormHelper::start() + * Reintroduce `auto_start` session config flag to instruct the `SessionListener` to manually start session + * Added session config option `on_demand_mode` to control session start on demand. 2.2.0 ----- diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index d75107355a213..cd54ffddfda35 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -198,6 +198,16 @@ private function addSessionSection(ArrayNodeDefinition $rootNode) ->info('session configuration') ->canBeUnset() ->children() + ->booleanNode('auto_start') + ->defaultFalse() + ->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() ->scalarNode('name')->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 2848714cd952e..f65d5d87ba998 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -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; @@ -314,6 +315,14 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c $container->setParameter('session.storage.options', $options); + // this controls the SessionListener to start session + $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']); + + $container->setParameter('session.storage.mock_name', $config['mock_name']); + // session handler (the internal callback registered with PHP session management) if (null == $config['handler_id']) { // Set the handler class to be null diff --git a/src/Symfony/Bundle/FrameworkBundle/EventListener/SessionListener.php b/src/Symfony/Bundle/FrameworkBundle/EventListener/SessionListener.php index 7b5ce51db997d..f594a85ddd70f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/EventListener/SessionListener.php +++ b/src/Symfony/Bundle/FrameworkBundle/EventListener/SessionListener.php @@ -29,10 +29,12 @@ class SessionListener implements EventSubscriberInterface * @var ContainerInterface */ private $container; + private $autoStart; - public function __construct(ContainerInterface $container) + public function __construct(ContainerInterface $container, $autoStart = false) { $this->container = $container; + $this->autoStart = $autoStart; } public function onKernelRequest(GetResponseEvent $event) @@ -46,7 +48,11 @@ public function onKernelRequest(GetResponseEvent $event) return; } - $request->setSession($this->container->get('session')); + $request->setSession($session = $this->container->get('session')); + + if ($this->autoStart || $request->hasPreviousSession()) { + $session->start(); + } } public static function getSubscribedEvents() 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 675a24b2c620f..982991c17baf7 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 @@ -77,6 +77,9 @@ + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml index de45365751be9..6e4d4876b8112 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml @@ -8,6 +8,7 @@ Symfony\Component\HttpFoundation\Session\Session Symfony\Component\HttpFoundation\Session\Flash\FlashBag Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag + Symfony\Component\HttpFoundation\Session\Storage\MetadataBag Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage @@ -25,6 +26,8 @@ %session.storage.options% + + %session.storage.on_demand_mode% @@ -32,11 +35,15 @@ +