From 1fd66f3cdf55ea63b3c1ee968cd2d0d774c9ea4e Mon Sep 17 00:00:00 2001 From: Drak Date: Fri, 29 Jun 2012 17:34:28 +0100 Subject: [PATCH 1/4] [FrameworkBundle] Remove 'auto_start' configuration parameter. --- src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md | 2 ++ .../FrameworkBundle/DependencyInjection/Configuration.php | 2 +- .../DependencyInjection/FrameworkExtension.php | 5 +---- .../Bundle/FrameworkBundle/EventListener/SessionListener.php | 1 - .../Fixtures/php/deprecated_merge_full.php | 1 - .../Fixtures/php/deprecated_merge_partial.php | 1 - .../Tests/DependencyInjection/Fixtures/php/full.php | 1 - .../Fixtures/yml/deprecated_merge_full.yml | 1 - .../Fixtures/yml/deprecated_merge_partial.yml | 1 - .../Tests/DependencyInjection/Fixtures/yml/full.yml | 1 - .../Tests/DependencyInjection/FrameworkExtensionTest.php | 1 - .../Tests/Templating/Helper/SessionHelperTest.php | 1 + 12 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 4a28859c35..10732f2b5d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -32,3 +32,5 @@ CHANGELOG `gc_probability`/`gc_divisor` chance of being run. The `gc_maxlifetime` defines how long a session can idle for. It is different from cookie lifetime which declares how long a cookie can be stored on the remote client. + * Removed 'auto_start' configuration parameter from session config. The session will + start on demand. diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 7ffdca13cf..6bf3156e09 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -176,7 +176,7 @@ class Configuration implements ConfigurationInterface ->info('session configuration') ->canBeUnset() ->children() - ->booleanNode('auto_start')->defaultFalse()->end() + ->booleanNode('auto_start')->info('DEPRECATED! Session wil start on demand')->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 60bd4e42df..5197201e06 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -291,13 +291,10 @@ class FrameworkExtension extends Extension { $loader->load('session.xml'); - // session - $container->getDefinition('session_listener')->addArgument($config['auto_start']); - // session storage $container->setAlias('session.storage', $config['storage_id']); $options = array(); - foreach (array('name', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'auto_start', 'gc_maxlifetime', 'gc_probability', 'gc_divisor') as $key) { + foreach (array('name', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'gc_maxlifetime', 'gc_probability', 'gc_divisor') as $key) { if (isset($config[$key])) { $options[$key] = $config[$key]; } diff --git a/src/Symfony/Bundle/FrameworkBundle/EventListener/SessionListener.php b/src/Symfony/Bundle/FrameworkBundle/EventListener/SessionListener.php index ad396347d5..0c0260b243 100644 --- a/src/Symfony/Bundle/FrameworkBundle/EventListener/SessionListener.php +++ b/src/Symfony/Bundle/FrameworkBundle/EventListener/SessionListener.php @@ -41,7 +41,6 @@ class SessionListener implements EventSubscriberInterface public function __construct(ContainerInterface $container, $autoStart = false) { $this->container = $container; - $this->autoStart = $autoStart; } public function onKernelRequest(GetResponseEvent $event) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/deprecated_merge_full.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/deprecated_merge_full.php index 5119fbdbab..07b07fa552 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/deprecated_merge_full.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/deprecated_merge_full.php @@ -3,7 +3,6 @@ $container->loadFromExtension('framework', array( 'secret' => 's3cr3t', 'session' => array( - 'auto_start' => true, 'storage_id' => 'session.storage.native', 'handler_id' => 'session.handler.native_file', 'name' => '_SYMFONY', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/deprecated_merge_partial.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/deprecated_merge_partial.php index b15ea893f0..8706696e58 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/deprecated_merge_partial.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/deprecated_merge_partial.php @@ -3,7 +3,6 @@ $container->loadFromExtension('framework', array( 'secret' => 's3cr3t', 'session' => array( - 'auto_start' => true, 'storage_id' => 'session.storage.native', 'handler_id' => 'session.handler.native_file', 'name' => '_SYMFONY', 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 c9ee3d996e..b4c1acc52e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -19,7 +19,6 @@ $container->loadFromExtension('framework', array( 'type' => 'xml', ), 'session' => array( - 'auto_start' => true, 'storage_id' => 'session.storage.native', 'handler_id' => 'session.handler.native_file', 'name' => '_SYMFONY', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/deprecated_merge_full.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/deprecated_merge_full.yml index e5ec05fbf6..af6abaf276 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/deprecated_merge_full.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/deprecated_merge_full.yml @@ -1,7 +1,6 @@ framework: secret: s3cr3t session: - auto_start: true storage_id: session.storage.native handler_id: session.handler.native_file name: _SYMFONY diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/deprecated_merge_partial.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/deprecated_merge_partial.yml index 67ea8bc44b..765719c521 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/deprecated_merge_partial.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/deprecated_merge_partial.yml @@ -1,7 +1,6 @@ framework: secret: s3cr3t session: - auto_start: true storage_id: session.storage.native handler_id: session.handler.native_file name: _SYMFONY 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 5e97a55853..f10bb5ccfe 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -13,7 +13,6 @@ framework: resource: %kernel.root_dir%/config/routing.xml type: xml session: - auto_start: true storage_id: session.storage.native handler_id: session.handler.native_file name: _SYMFONY diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 548b7e6b3c..385ece0c8c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -77,7 +77,6 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertTrue($container->hasDefinition('session'), '->registerSessionConfiguration() loads session.xml'); $this->assertEquals('fr', $container->getParameter('kernel.default_locale')); - $this->assertTrue($container->getDefinition('session_listener')->getArgument(1)); $this->assertEquals('session.storage.native', (string) $container->getAlias('session.storage')); $this->assertEquals('session.handler.native_file', (string) $container->getAlias('session.handler')); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/SessionHelperTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/SessionHelperTest.php index 4bd043ed59..3b9001c619 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/SessionHelperTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/SessionHelperTest.php @@ -25,6 +25,7 @@ class SessionHelperTest extends \PHPUnit_Framework_TestCase $this->request = new Request(); $session = new Session(new MockArraySessionStorage()); + $session->start(); $session->set('foobar', 'bar'); $session->getFlashBag()->set('notice', 'bar'); From dcac5d7fd6d769e25dd3f55357c6636a8bad4693 Mon Sep 17 00:00:00 2001 From: Drak Date: Fri, 29 Jun 2012 18:04:40 +0100 Subject: [PATCH 2/4] [HttpFoundation] Corrected docblocks and properties. --- .../Session/Storage/MockArraySessionStorage.php | 5 +++++ .../Component/HttpFoundation/Tests/Session/SessionTest.php | 3 +-- .../Tests/Session/Storage/MockArraySessionStorageTest.php | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php index 45725522e8..9ab8bea8e9 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php @@ -58,6 +58,11 @@ class MockArraySessionStorage implements SessionStorageInterface */ protected $metadataBag; + /** + * @var array + */ + protected $bags; + /** * Constructor. * diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php index 2f2b26fb3e..7bdc127fdb 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpFoundation\Tests\Session; use Symfony\Component\HttpFoundation\Session\Session; -use Symfony\Component\HttpFoundation\Session\MetadataBag; use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; @@ -260,7 +259,7 @@ class SessionTest extends \PHPUnit_Framework_TestCase } /** - * @covers Symfony\Component\HttpFoundation\Session\Session::count + * @covers \Symfony\Component\HttpFoundation\Session\Session::count */ public function testGetCount() { diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockArraySessionStorageTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockArraySessionStorageTest.php index 0da4805ff3..c9b2a7480c 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockArraySessionStorageTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockArraySessionStorageTest.php @@ -28,12 +28,12 @@ class MockArraySessionStorageTest extends \PHPUnit_Framework_TestCase private $storage; /** - * @var array + * @var AttributeBag */ private $attributes; /** - * @var array + * @var FlashBag */ private $flashes; From 19eeac88cae1441d446a16522c82526c7c1c9280 Mon Sep 17 00:00:00 2001 From: Drak Date: Fri, 29 Jun 2012 18:05:14 +0100 Subject: [PATCH 3/4] [HttpFoundation] Removed erroneous reliance on session.auto_start --- .../Session/Storage/NativeSessionStorage.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php index d5bcca14fb..965c786f85 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php @@ -61,7 +61,9 @@ class NativeSessionStorage implements SessionStorageInterface * @see http://php.net/session.configuration for options * but we omit 'session.' from the beginning of the keys for convenience. * - * auto_start, "0" + * ("auto_start", is not supported as it tells PHP to start a session before + * PHP starts to execute user-land code. Setting during runtime has no effect). + * * cache_limiter, "nocache" (use "0" to prevent headers from being sent entirely). * cookie_domain, "" * cookie_httponly, "" @@ -95,8 +97,6 @@ class NativeSessionStorage implements SessionStorageInterface */ public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null) { - // sensible defaults - ini_set('session.auto_start', 0); // by default we prefer to explicitly start the session using the class. ini_set('session.cache_limiter', ''); // disable by default because it's managed by HeaderBag (if used) ini_set('session.use_cookies', 1); @@ -256,10 +256,10 @@ class NativeSessionStorage implements SessionStorageInterface throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name)); } - if (ini_get('session.auto_start') && !$this->started) { - $this->start(); - } elseif ($this->saveHandler->isActive() && !$this->started) { + if ($this->saveHandler->isActive() && !$this->started) { $this->loadSession(); + } elseif (!$this->started) { + $this->start(); } return $this->bags[$name]; @@ -302,7 +302,7 @@ class NativeSessionStorage implements SessionStorageInterface public function setOptions(array $options) { $validOptions = array_flip(array( - 'auto_start', 'cache_limiter', 'cookie_domain', 'cookie_httponly', + 'cache_limiter', 'cookie_domain', 'cookie_httponly', 'cookie_lifetime', 'cookie_path', 'cookie_secure', 'entropy_file', 'entropy_length', 'gc_divisor', 'gc_maxlifetime', 'gc_probability', 'hash_bits_per_character', From 911db69bfe76c860b70cf87ae1e4780df7691b63 Mon Sep 17 00:00:00 2001 From: Drak Date: Fri, 29 Jun 2012 20:13:19 +0100 Subject: [PATCH 4/4] [FrameworkBundle] Typo fix --- .../FrameworkBundle/DependencyInjection/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 6bf3156e09..38e064584a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -176,7 +176,7 @@ class Configuration implements ConfigurationInterface ->info('session configuration') ->canBeUnset() ->children() - ->booleanNode('auto_start')->info('DEPRECATED! Session wil start on demand')->end() + ->booleanNode('auto_start')->info('DEPRECATED! Session starts on demand')->end() ->scalarNode('storage_id')->defaultValue('session.storage.native')->end() ->scalarNode('handler_id')->defaultValue('session.handler.native_file')->end() ->scalarNode('name')->end()