Skip to content

Commit f275707

Browse files
Alexandru Furculitaafurculita
authored andcommitted
[HttpFoundation] Deprecate <5.4 session functionality
Signed-off-by: Alexandru Furculita <alex@furculita.net>
1 parent c4159b1 commit f275707

16 files changed

+71
-36
lines changed

UPGRADE-3.4.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,30 @@ FrameworkBundle
202202
`TranslationDebugCommand`, `TranslationUpdateCommand`, `XliffLintCommand`
203203
and `YamlLintCommand` classes have been marked as final
204204

205+
HttpFoundation
206+
----------
207+
208+
* The `Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler`
209+
class has been deprecated and will be removed in 4.0. Use the `\SessionHandler` class instead.
210+
211+
* The `Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy` class has been
212+
deprecated and will be removed in 4.0. Use the `Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy`
213+
class instead.
214+
215+
* The `Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy` class has been
216+
deprecated and will be removed in 4.0. Use the `Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy`
217+
class instead.
218+
219+
* The `Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy::isSessionHandlerInterface()`
220+
method has been deprecated and will be removed in 4.0.
221+
222+
* The `Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy::isWrapper()`
223+
method has been deprecated and will be removed in 4.0. You can check explicitly if the proxy wraps
224+
a `\SessionHandler` instance.
225+
226+
* `NativeSessionStorage::setSaveHandler()` now takes an instance of `\SessionHandlerInterface` as argument.
227+
Not passing it is deprecated and will throw a `TypeError` in 4.0.
228+
205229
HttpKernel
206230
----------
207231

src/Symfony/Component/HttpFoundation/CHANGELOG.md

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

4+
3.4.0
5+
-----
6+
7+
* deprecated the `NativeSessionHandler` class,
8+
* deprecated the `AbstractProxy` and `NativeProxy` classes in favor of `SessionHandlerProxy` class,
9+
* deprecated the `SessionHandlerProxy::isSessionHandlerInterface()` and `SessionHandlerProxy::isWrapper()` methods,
10+
* deprecated setting session save handlers that do not implement `\SessionHandlerInterface` in `NativeSessionStorage::setSaveHandler()`
11+
412
3.3.0
513
-----
614

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 <drak@zikula.org>
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 <markus.bachmann@bachi.biz>
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 <drak@zikula.org>
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 <drak@zikula.org>

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

Lines changed: 9 additions & 9 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

@@ -97,9 +96,9 @@ class NativeSessionStorage implements SessionStorageInterface
9796
* trans_sid_hosts, $_SERVER['HTTP_HOST']
9897
* trans_sid_tags, "a=href,area=href,frame=src,form="
9998
*
100-
* @param array $options Session configuration options
101-
* @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $handler
102-
* @param MetadataBag $metaBag MetadataBag
99+
* @param array $options Session configuration options
100+
* @param AbstractProxy|\SessionHandlerInterface|null $handler
101+
* @param MetadataBag $metaBag MetadataBag
103102
*/
104103
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
105104
{
@@ -276,7 +275,7 @@ public function getBag($name)
276275
throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name));
277276
}
278277

279-
if ($this->saveHandler->isActive() && !$this->started) {
278+
if (!$this->started && $this->saveHandler->isActive()) {
280279
$this->loadSession();
281280
} elseif (!$this->started) {
282281
$this->start();
@@ -358,7 +357,7 @@ public function setOptions(array $options)
358357
* ini_set('session.save_handler', 'files');
359358
* ini_set('session.save_path', '/tmp');
360359
*
361-
* or pass in a NativeSessionHandler instance which configures session.save_handler in the
360+
* or pass in a \SessionHandler instance which configures session.save_handler in the
362361
* constructor, for a template see NativeFileSessionHandler or use handlers in
363362
* composer package drak/native-session
364363
*
@@ -367,17 +366,16 @@ public function setOptions(array $options)
367366
* @see http://php.net/sessionhandler
368367
* @see http://github.com/drak/NativeSession
369368
*
370-
* @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $saveHandler
369+
* @param AbstractProxy|\SessionHandlerInterface|null $saveHandler
371370
*
372371
* @throws \InvalidArgumentException
373372
*/
374373
public function setSaveHandler($saveHandler = null)
375374
{
376375
if (!$saveHandler instanceof AbstractProxy &&
377-
!$saveHandler instanceof NativeSessionHandler &&
378376
!$saveHandler instanceof \SessionHandlerInterface &&
379377
null !== $saveHandler) {
380-
throw new \InvalidArgumentException('Must be instance of AbstractProxy or NativeSessionHandler; implement \SessionHandlerInterface; or be null.');
378+
throw new \InvalidArgumentException('Must be instance of AbstractProxy; implement \SessionHandlerInterface; or be null.');
381379
}
382380

383381
// Wrap $saveHandler in proxy and prevent double wrapping of proxy
@@ -390,6 +388,8 @@ public function setSaveHandler($saveHandler = null)
390388

391389
if ($this->saveHandler instanceof \SessionHandlerInterface) {
392390
session_set_save_handler($this->saveHandler, false);
391+
} else {
392+
@trigger_error('Using session save handlers that do not implement \SessionHandlerInterface is deprecated since version 3.4 and will be removed in 4.0.', E_USER_DEPRECATED);
393393
}
394394
}
395395

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

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

1414
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
15-
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
1615

1716
/**
1817
* Allows session to be started by PHP and managed by Symfony.
@@ -24,8 +23,8 @@ class PhpBridgeSessionStorage extends NativeSessionStorage
2423
/**
2524
* Constructor.
2625
*
27-
* @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $handler
28-
* @param MetadataBag $metaBag MetadataBag
26+
* @param AbstractProxy|\SessionHandlerInterface|null $handler
27+
* @param MetadataBag $metaBag MetadataBag
2928
*/
3029
public function __construct($handler = null, MetadataBag $metaBag = null)
3130
{

0 commit comments

Comments
 (0)