Skip to content

Commit 3deb394

Browse files
Alexandru FurculitaTobion
authored andcommitted
[HttpFoundation] Deprecate compatibility with PHP <5.4 sessions
1 parent f617882 commit 3deb394

23 files changed

+79
-90
lines changed

UPGRADE-3.4.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,24 @@ FrameworkBundle
205205
`TranslationDebugCommand`, `TranslationUpdateCommand`, `XliffLintCommand`
206206
and `YamlLintCommand` classes have been marked as final
207207

208+
HttpFoundation
209+
--------------
210+
211+
* The `Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler`
212+
class has been deprecated and will be removed in 4.0. Use the `\SessionHandler` class instead.
213+
214+
* The `Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy` class has been
215+
deprecated and will be removed in 4.0. Use your `\SessionHandlerInterface` implementation directly.
216+
217+
* The `Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy` class has been
218+
deprecated and will be removed in 4.0. Use your `\SessionHandlerInterface` implementation directly.
219+
220+
* The `Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy` class has been
221+
deprecated and will be removed in 4.0. Use your `\SessionHandlerInterface` implementation directly.
222+
223+
* `NativeSessionStorage::setSaveHandler()` now takes an instance of `\SessionHandlerInterface` as argument.
224+
Not passing it is deprecated and will throw a `TypeError` in 4.0.
225+
208226
HttpKernel
209227
----------
210228

UPGRADE-4.0.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,13 @@ HttpFoundation
524524
* The ability to check only for cacheable HTTP methods using `Request::isMethodSafe()` is
525525
not supported anymore, use `Request::isMethodCacheable()` instead.
526526

527+
* The `Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler`,
528+
`Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy`,
529+
`Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy` and
530+
`Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy` classes have been removed.
531+
532+
* `NativeSessionStorage::setSaveHandler()` now requires an instance of `\SessionHandlerInterface` as argument.
533+
527534
HttpKernel
528535
----------
529536

src/Symfony/Bridge/Twig/Tests/AppVariableTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ public function testEnvironment()
4747

4848
public function testGetSession()
4949
{
50+
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
5051
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
51-
$request->method('getSession')->willReturn($session = new Session());
52+
$request->method('getSession')->willReturn($session);
5253

5354
$this->setRequestStack($request);
5455

@@ -167,8 +168,9 @@ public function testGetFlashesWithNoRequest()
167168

168169
public function testGetFlashesWithNoSessionStarted()
169170
{
171+
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
170172
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
171-
$request->method('getSession')->willReturn(new Session());
173+
$request->method('getSession')->willReturn($session);
172174

173175
$this->setRequestStack($request);
174176

@@ -257,7 +259,7 @@ private function setFlashMessages()
257259
$flashBag = new FlashBag();
258260
$flashBag->initialize($flashMessages);
259261

260-
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')->getMock();
262+
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')->disableOriginalConstructor()->getMock();
261263
$session->method('isStarted')->willReturn(true);
262264
$session->method('getFlashBag')->willReturn($flashBag);
263265

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTraitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public function testRedirectToRoute()
376376
public function testAddFlash()
377377
{
378378
$flashBag = new FlashBag();
379-
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')->getMock();
379+
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')->disableOriginalConstructor()->getMock();
380380
$session->expects($this->once())->method('getFlashBag')->willReturn($flashBag);
381381

382382
$container = new Container();

src/Symfony/Component/HttpFoundation/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
CHANGELOG
22
=========
33

4+
3.4.0
5+
-----
6+
7+
* deprecated the `NativeSessionHandler` class,
8+
* deprecated the `AbstractProxy`, `NativeProxy` and `SessionHandlerProxy` classes,
9+
* deprecated setting session save handlers that do not implement `\SessionHandlerInterface` in `NativeSessionStorage::setSaveHandler()`
10+
411
3.3.0
512
-----
613

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcacheSessionHandler.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
1313

1414
/**
15-
* MemcacheSessionHandler.
16-
*
1715
* @author Drak <[email protected]>
1816
*/
1917
class MemcacheSessionHandler implements \SessionHandlerInterface

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
1313

1414
/**
15-
* MemcachedSessionHandler.
16-
*
1715
* Memcached based session storage handler based on the Memcached class
1816
* provided by the PHP memcached extension.
1917
*

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
1313

1414
/**
15-
* MongoDB session handler.
16-
*
1715
* @author Markus Bachmann <[email protected]>
1816
*/
1917
class MongoDbSessionHandler implements \SessionHandlerInterface

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeFileSessionHandler.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,21 @@
1212
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
1313

1414
/**
15-
* NativeFileSessionHandler.
16-
*
1715
* Native session handler using PHP's built in file storage.
1816
*
1917
* @author Drak <[email protected]>
2018
*/
2119
class NativeFileSessionHandler extends NativeSessionHandler
2220
{
2321
/**
24-
* Constructor.
25-
*
2622
* @param string $savePath Path of directory to save session files
2723
* Default null will leave setting as defined by PHP.
2824
* '/path', 'N;/path', or 'N;octal-mode;/path
2925
*
3026
* @see http://php.net/session.configuration.php#ini.session.save-path for further details.
3127
*
3228
* @throws \InvalidArgumentException On invalid $savePath
29+
* @throws \RuntimeException When failing to create the save directory
3330
*/
3431
public function __construct($savePath = null)
3532
{

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeSessionHandler.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\NativeSessionHandler class is deprecated since version 3.4 and will be removed in 4.0. Use the \SessionHandler class instead.', E_USER_DEPRECATED);
15+
1416
/**
15-
* Adds SessionHandler functionality if available.
16-
*
17+
* @deprecated since version 3.4, to be removed in 4.0. Use \SessionHandler instead.
1718
* @see http://php.net/sessionhandler
1819
*/
1920
class NativeSessionHandler extends \SessionHandler

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NullSessionHandler.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
1313

1414
/**
15-
* NullSessionHandler.
16-
*
1715
* Can be used in unit testing or in a situations where persisted sessions are not desired.
1816
*
1917
* @author Drak <[email protected]>

src/Symfony/Component/HttpFoundation/Session/Storage/MetadataBag.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ class MetadataBag implements SessionBagInterface
5454
private $updateThreshold;
5555

5656
/**
57-
* Constructor.
58-
*
5957
* @param string $storageKey The key used to store bag in the session
6058
* @param int $updateThreshold The time to wait between two UPDATED updates
6159
*/

src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ class MockArraySessionStorage implements SessionStorageInterface
6363
protected $bags = array();
6464

6565
/**
66-
* Constructor.
67-
*
6866
* @param string $name Session name
6967
* @param MetadataBag $metaBag MetadataBag instance
7068
*/

src/Symfony/Component/HttpFoundation/Session/Storage/MockFileSessionStorage.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class MockFileSessionStorage extends MockArraySessionStorage
3030
private $savePath;
3131

3232
/**
33-
* Constructor.
34-
*
3533
* @param string $savePath Path of directory to save session files
3634
* @param string $name Session name
3735
* @param MetadataBag $metaBag MetadataBag instance

src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Component\Debug\Exception\ContextErrorException;
1515
use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
16-
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
1716
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
1817
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
1918

@@ -25,8 +24,6 @@
2524
class NativeSessionStorage implements SessionStorageInterface
2625
{
2726
/**
28-
* Array of SessionBagInterface.
29-
*
3027
* @var SessionBagInterface[]
3128
*/
3229
protected $bags;
@@ -42,7 +39,7 @@ class NativeSessionStorage implements SessionStorageInterface
4239
protected $closed = false;
4340

4441
/**
45-
* @var AbstractProxy
42+
* @var AbstractProxy|\SessionHandlerInterface
4643
*/
4744
protected $saveHandler;
4845

@@ -52,8 +49,6 @@ class NativeSessionStorage implements SessionStorageInterface
5249
protected $metadataBag;
5350

5451
/**
55-
* Constructor.
56-
*
5752
* Depending on how you want the storage driver to behave you probably
5853
* want to override this constructor entirely.
5954
*
@@ -97,9 +92,9 @@ class NativeSessionStorage implements SessionStorageInterface
9792
* trans_sid_hosts, $_SERVER['HTTP_HOST']
9893
* trans_sid_tags, "a=href,area=href,frame=src,form="
9994
*
100-
* @param array $options Session configuration options
101-
* @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $handler
102-
* @param MetadataBag $metaBag MetadataBag
95+
* @param array $options Session configuration options
96+
* @param \SessionHandlerInterface|null $handler
97+
* @param MetadataBag $metaBag MetadataBag
10398
*/
10499
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
105100
{
@@ -116,7 +111,7 @@ public function __construct(array $options = array(), $handler = null, MetadataB
116111
/**
117112
* Gets the save handler instance.
118113
*
119-
* @return AbstractProxy
114+
* @return AbstractProxy|\SessionHandlerInterface
120115
*/
121116
public function getSaveHandler()
122117
{
@@ -276,7 +271,7 @@ public function getBag($name)
276271
throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name));
277272
}
278273

279-
if ($this->saveHandler->isActive() && !$this->started) {
274+
if (!$this->started && $this->saveHandler->isActive()) {
280275
$this->loadSession();
281276
} elseif (!$this->started) {
282277
$this->start();
@@ -358,7 +353,7 @@ public function setOptions(array $options)
358353
* ini_set('session.save_handler', 'files');
359354
* ini_set('session.save_path', '/tmp');
360355
*
361-
* or pass in a NativeSessionHandler instance which configures session.save_handler in the
356+
* or pass in a \SessionHandler instance which configures session.save_handler in the
362357
* constructor, for a template see NativeFileSessionHandler or use handlers in
363358
* composer package drak/native-session
364359
*
@@ -367,17 +362,23 @@ public function setOptions(array $options)
367362
* @see http://php.net/sessionhandler
368363
* @see http://github.com/drak/NativeSession
369364
*
370-
* @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $saveHandler
365+
* @param \SessionHandlerInterface|null $saveHandler
371366
*
372367
* @throws \InvalidArgumentException
373368
*/
374369
public function setSaveHandler($saveHandler = null)
375370
{
376371
if (!$saveHandler instanceof AbstractProxy &&
377-
!$saveHandler instanceof NativeSessionHandler &&
378372
!$saveHandler instanceof \SessionHandlerInterface &&
379373
null !== $saveHandler) {
380-
throw new \InvalidArgumentException('Must be instance of AbstractProxy or NativeSessionHandler; implement \SessionHandlerInterface; or be null.');
374+
throw new \InvalidArgumentException('Must be instance of AbstractProxy; implement \SessionHandlerInterface; or be null.');
375+
}
376+
377+
if ($saveHandler instanceof AbstractProxy) {
378+
@trigger_error(
379+
'Using session save handlers that are instances of AbstractProxy is deprecated since version 3.4 and will be removed in 4.0.',
380+
E_USER_DEPRECATED
381+
);
381382
}
382383

383384
// Wrap $saveHandler in proxy and prevent double wrapping of proxy

src/Symfony/Component/HttpFoundation/Session/Storage/PhpBridgeSessionStorage.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
namespace Symfony\Component\HttpFoundation\Session\Storage;
1313

14-
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
15-
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
16-
1714
/**
1815
* Allows session to be started by PHP and managed by Symfony.
1916
*
@@ -22,10 +19,8 @@
2219
class PhpBridgeSessionStorage extends NativeSessionStorage
2320
{
2421
/**
25-
* Constructor.
26-
*
27-
* @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $handler
28-
* @param MetadataBag $metaBag MetadataBag
22+
* @param \SessionHandlerInterface|null $handler
23+
* @param MetadataBag $metaBag MetadataBag
2924
*/
3025
public function __construct($handler = null, MetadataBag $metaBag = null)
3126
{

src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/AbstractProxy.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\AbstractProxy class is deprecated since version 3.4 and will be removed in 4.0. Use your session handler implementation directly.', E_USER_DEPRECATED);
15+
1416
/**
15-
* AbstractProxy.
17+
* @deprecated since version 3.4, to be removed in 4.0. Use your session handler implementation directly.
1618
*
1719
* @author Drak <[email protected]>
1820
*/

src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/NativeProxy.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\NativeProxy class is deprecated since version 3.4 and will be removed in 4.0. Use your session handler implementation directly.', E_USER_DEPRECATED);
15+
1416
/**
15-
* NativeProxy.
17+
* This proxy is built-in session handlers in PHP 5.3.x.
1618
*
17-
* This proxy is built-in session handlers in PHP 5.3.x
19+
* @deprecated since version 3.4, to be removed in 4.0. Use your session handler implementation directly.
1820
*
1921
* @author Drak <[email protected]>
2022
*/

src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\SessionHandlerProxy class is deprecated since version 3.4 and will be removed in 4.0. Use your session handler implementation directly.', E_USER_DEPRECATED);
15+
1416
/**
15-
* SessionHandler proxy.
17+
* @deprecated since version 3.4, to be removed in 4.0. Use your session handler implementation directly.
1618
*
1719
* @author Drak <[email protected]>
1820
*/
@@ -23,11 +25,6 @@ class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterf
2325
*/
2426
protected $handler;
2527

26-
/**
27-
* Constructor.
28-
*
29-
* @param \SessionHandlerInterface $handler
30-
*/
3128
public function __construct(\SessionHandlerInterface $handler)
3229
{
3330
$this->handler = $handler;

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeSessionHandlerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*
2222
* @runTestsInSeparateProcesses
2323
* @preserveGlobalState disabled
24+
* @group legacy
2425
*/
2526
class NativeSessionHandlerTest extends TestCase
2627
{

0 commit comments

Comments
 (0)