Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 71a92a2

Browse files
author
Alexandru Furculita
committed
[HttpFoundation] Deprecate <5.4 session functionality
1 parent c4159b1 commit 71a92a2

16 files changed

+66
-36
lines changed

UPGRADE-3.4.md

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

205+
HttpKernel
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+
* the `Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy` class has been
211+
deprecated and will be removed in 4.0. Use the `Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy`
212+
class instead.
213+
* the `Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy` class has been
214+
deprecated and will be removed in 4.0. Use the `Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy`
215+
class instead.
216+
* the `Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy::isSessionHandlerInterface()`
217+
method has been deprecated and will be removed in 4.0.
218+
* the `Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy::isWrapper()`
219+
method has been deprecated and will be removed in 4.0. You can check explicitly if the proxy wraps
220+
a `\SessionHandler` instance.
221+
* `NativeSessionStorage::setSaveHandler()` now takes an instance of `\SessionHandlerInterface` as argument.
222+
Not passing it is deprecated and will throw a `TypeError` in 4.0.
223+
205224
HttpKernel
206225
----------
207226

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 <[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/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
{

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
1313

1414
/**
15-
* AbstractProxy.
15+
* @deprecated since version 3.4, to be removed in 4.0. Use SessionHandlerProxy instead.
1616
*
1717
* @author Drak <[email protected]>
1818
*/
@@ -21,6 +21,8 @@ abstract class AbstractProxy
2121
/**
2222
* Flag if handler wraps an internal PHP session handler (using \SessionHandler).
2323
*
24+
* @deprecated since version 3.4 and will be removed in 4.0.
25+
*
2426
* @var bool
2527
*/
2628
protected $wrapper = false;
@@ -43,20 +45,28 @@ public function getSaveHandlerName()
4345
/**
4446
* Is this proxy handler and instance of \SessionHandlerInterface.
4547
*
48+
* @deprecated since version 3.4 and will be removed in 4.0.
49+
*
4650
* @return bool
4751
*/
4852
public function isSessionHandlerInterface()
4953
{
54+
@trigger_error('isSessionHandlerInterface() is deprecated since version 3.4 and will be removed in 4.0. A session handler proxy should always implement \SessionHandlerInterface.', E_USER_DEPRECATED);
55+
5056
return $this instanceof \SessionHandlerInterface;
5157
}
5258

5359
/**
5460
* Returns true if this handler wraps an internal PHP session save handler using \SessionHandler.
5561
*
62+
* @deprecated since version 3.4 and will be removed in 4.0.
63+
*
5664
* @return bool
5765
*/
5866
public function isWrapper()
5967
{
68+
@trigger_error('isWrapper() is deprecated since version 3.4 and will be removed in 4.0. You should explicitly check if the handler proxy wraps a \SessionHandler instance.', E_USER_DEPRECATED);
69+
6070
return $this->wrapper;
6171
}
6272

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 the Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy class instead.', 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 SessionHandlerProxy instead.
1820
*
1921
* @author Drak <[email protected]>
2022
*/

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

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

1414
/**
15-
* SessionHandler proxy.
16-
*
1715
* @author Drak <[email protected]>
1816
*/
1917
class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface
@@ -23,11 +21,6 @@ class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterf
2321
*/
2422
protected $handler;
2523

26-
/**
27-
* Constructor.
28-
*
29-
* @param \SessionHandlerInterface $handler
30-
*/
3124
public function __construct(\SessionHandlerInterface $handler)
3225
{
3326
$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
{

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/AbstractProxyTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,19 @@ public function testGetSaveHandlerName()
7474
$this->assertNull($this->proxy->getSaveHandlerName());
7575
}
7676

77+
/**
78+
* @group legacy
79+
*/
7780
public function testIsSessionHandlerInterface()
7881
{
7982
$this->assertFalse($this->proxy->isSessionHandlerInterface());
8083
$sh = new ConcreteSessionHandlerInterfaceProxy();
8184
$this->assertTrue($sh->isSessionHandlerInterface());
8285
}
8386

87+
/**
88+
* @group legacy
89+
*/
8490
public function testIsWrapper()
8591
{
8692
$this->assertFalse($this->proxy->isWrapper());

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/NativeProxyTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
/**
1818
* Test class for NativeProxy.
1919
*
20+
* @group legacy
21+
*
2022
* @author Drak <[email protected]>
2123
*/
2224
class NativeProxyTest extends TestCase

0 commit comments

Comments
 (0)