Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpFoundation] Deprecate compatibility with PHP <5.4 sessions #24239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[HttpFoundation] Deprecate <5.4 session functionality
Signed-off-by: Alexandru Furculita <alex@furculita.net>
  • Loading branch information
Alexandru Furculita authored and afurculita committed Sep 24, 2017
commit 73a1235c176ebb09e8f402343e90d5e6c9dff872
24 changes: 24 additions & 0 deletions 24 UPGRADE-3.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,30 @@ FrameworkBundle
`TranslationDebugCommand`, `TranslationUpdateCommand`, `XliffLintCommand`
and `YamlLintCommand` classes have been marked as final

HttpFoundation
--------------

* The `Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler`
class has been deprecated and will be removed in 4.0. Use the `\SessionHandler` class instead.

* The `Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy` class has been
deprecated and will be removed in 4.0. Use the `Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy`
class instead.

* The `Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy` class has been
deprecated and will be removed in 4.0. Use the `Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy`
class instead.

* The `Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy::isSessionHandlerInterface()`
method has been deprecated and will be removed in 4.0.

* The `Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy::isWrapper()`
method has been deprecated and will be removed in 4.0. You can check explicitly if the proxy wraps
a `\SessionHandler` instance.

* `NativeSessionStorage::setSaveHandler()` now takes an instance of `\SessionHandlerInterface` as argument.
Not passing it is deprecated and will throw a `TypeError` in 4.0.

HttpKernel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate header (wrong rebase?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header should be HttpFoundation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

----------

Expand Down
9 changes: 9 additions & 0 deletions 9 UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,15 @@ HttpFoundation
* The ability to check only for cacheable HTTP methods using `Request::isMethodSafe()` is
not supported anymore, use `Request::isMethodCacheable()` instead.

* The `Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler`,
`Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy` and
`Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy` classes have been removed.

* The `SessionHandlerProxy::isSessionHandlerInterface()` and `SessionHandlerProxy::isWrapper()`
methods have been removed.

* `NativeSessionStorage::setSaveHandler()` now requires an instance of `\SessionHandlerInterface` as argument.

HttpKernel
----------

Expand Down
8 changes: 8 additions & 0 deletions 8 src/Symfony/Component/HttpFoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
CHANGELOG
=========

3.4.0
-----

* deprecated the `NativeSessionHandler` class,
* deprecated the `AbstractProxy` and `NativeProxy` classes in favor of `SessionHandlerProxy` class,
* deprecated the `SessionHandlerProxy::isSessionHandlerInterface()` and `SessionHandlerProxy::isWrapper()` methods,
* deprecated setting session save handlers that do not implement `\SessionHandlerInterface` in `NativeSessionStorage::setSaveHandler()`

3.3.0
-----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;

/**
* MemcacheSessionHandler.
*
* @author Drak <drak@zikula.org>
*/
class MemcacheSessionHandler implements \SessionHandlerInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;

/**
* MemcachedSessionHandler.
*
* Memcached based session storage handler based on the Memcached class
* provided by the PHP memcached extension.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;

/**
* MongoDB session handler.
*
* @author Markus Bachmann <markus.bachmann@bachi.biz>
*/
class MongoDbSessionHandler implements \SessionHandlerInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,21 @@
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;

/**
* NativeFileSessionHandler.
*
* Native session handler using PHP's built in file storage.
*
* @author Drak <drak@zikula.org>
*/
class NativeFileSessionHandler extends NativeSessionHandler
{
/**
* Constructor.
*
* @param string $savePath Path of directory to save session files
* Default null will leave setting as defined by PHP.
* '/path', 'N;/path', or 'N;octal-mode;/path
*
* @see http://php.net/session.configuration.php#ini.session.save-path for further details.
*
* @throws \InvalidArgumentException On invalid $savePath
* @throws \RuntimeException When failing to create the save directory
*/
public function __construct($savePath = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@

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

@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);

/**
* Adds SessionHandler functionality if available.
*
* @deprecated since version 3.4, to be removed in 4.0. Use \SessionHandler instead.
* @see http://php.net/sessionhandler
*/
class NativeSessionHandler extends \SessionHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;

/**
* NullSessionHandler.
*
* Can be used in unit testing or in a situations where persisted sessions are not desired.
*
* @author Drak <drak@zikula.org>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Symfony\Component\Debug\Exception\ContextErrorException;
use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;

Expand Down Expand Up @@ -97,9 +96,9 @@ class NativeSessionStorage implements SessionStorageInterface
* trans_sid_hosts, $_SERVER['HTTP_HOST']
* trans_sid_tags, "a=href,area=href,frame=src,form="
*
* @param array $options Session configuration options
* @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $handler
* @param MetadataBag $metaBag MetadataBag
* @param array $options Session configuration options
* @param AbstractProxy|\SessionHandlerInterface|null $handler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, AbstractProxy should not be documented anymore

* @param MetadataBag $metaBag MetadataBag
*/
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
{
Expand Down Expand Up @@ -276,7 +275,7 @@ public function getBag($name)
throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name));
}

if ($this->saveHandler->isActive() && !$this->started) {
if (!$this->started && $this->saveHandler->isActive()) {
$this->loadSession();
} elseif (!$this->started) {
$this->start();
Expand Down Expand Up @@ -358,7 +357,7 @@ public function setOptions(array $options)
* ini_set('session.save_handler', 'files');
* ini_set('session.save_path', '/tmp');
*
* or pass in a NativeSessionHandler instance which configures session.save_handler in the
* or pass in a \SessionHandler instance which configures session.save_handler in the
* constructor, for a template see NativeFileSessionHandler or use handlers in
* composer package drak/native-session
*
Expand All @@ -367,17 +366,16 @@ public function setOptions(array $options)
* @see http://php.net/sessionhandler
* @see http://github.com/drak/NativeSession
*
* @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $saveHandler
* @param AbstractProxy|\SessionHandlerInterface|null $saveHandler
*
* @throws \InvalidArgumentException
*/
public function setSaveHandler($saveHandler = null)
{
if (!$saveHandler instanceof AbstractProxy &&
!$saveHandler instanceof NativeSessionHandler &&
Copy link
Member

@nicolas-grekas nicolas-grekas Sep 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be reverted as that's a BC break, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, since Symfony 3.0, NativeSessionHandler always extends \SessionHandler. Thus now the rule !$saveHandler instanceof NativeSessionHandler is covered by !$saveHandler instanceof \SessionHandlerInterface

!$saveHandler instanceof \SessionHandlerInterface &&
null !== $saveHandler) {
throw new \InvalidArgumentException('Must be instance of AbstractProxy or NativeSessionHandler; implement \SessionHandlerInterface; or be null.');
throw new \InvalidArgumentException('Must be instance of AbstractProxy; implement \SessionHandlerInterface; or be null.');
}

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

if ($this->saveHandler instanceof \SessionHandlerInterface) {
session_set_save_handler($this->saveHandler, false);
} else {
@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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\HttpFoundation\Session\Storage;

use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;

/**
* Allows session to be started by PHP and managed by Symfony.
Expand All @@ -24,8 +23,8 @@ class PhpBridgeSessionStorage extends NativeSessionStorage
/**
* Constructor.
*
* @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $handler
* @param MetadataBag $metaBag MetadataBag
* @param AbstractProxy|\SessionHandlerInterface|null $handler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argument types that are deprecated should be removed from the doc

* @param MetadataBag $metaBag MetadataBag
*/
public function __construct($handler = null, MetadataBag $metaBag = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't you add a deprecated notice here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had one, but removed it because AbstractProxy is extended by SessionHandlerProxy and this will make the tests that use SessionHandlerProxy to not pass. I can't mark these tests as legacy. What's a good solution to have a deprecation notice here and tests pass?

/**
* AbstractProxy.
* @deprecated since version 3.4, to be removed in 4.0. Use SessionHandlerProxy instead.
*
* @author Drak <drak@zikula.org>
*/
Expand All @@ -21,6 +21,8 @@ abstract class AbstractProxy
/**
* Flag if handler wraps an internal PHP session handler (using \SessionHandler).
*
* @deprecated since version 3.4 and will be removed in 4.0.
*
* @var bool
*/
protected $wrapper = false;
Expand All @@ -43,20 +45,28 @@ public function getSaveHandlerName()
/**
* Is this proxy handler and instance of \SessionHandlerInterface.
*
* @deprecated since version 3.4 and will be removed in 4.0.
*
* @return bool
*/
public function isSessionHandlerInterface()
{
@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);

return $this instanceof \SessionHandlerInterface;
}

/**
* Returns true if this handler wraps an internal PHP session save handler using \SessionHandler.
*
* @deprecated since version 3.4 and will be removed in 4.0.
*
* @return bool
*/
public function isWrapper()
{
@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);

return $this->wrapper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

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

@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);

/**
* NativeProxy.
* This proxy is built-in session handlers in PHP 5.3.x.
*
* This proxy is built-in session handlers in PHP 5.3.x
* @deprecated since version 3.4, to be removed in 4.0. Use SessionHandlerProxy instead.
*
* @author Drak <drak@zikula.org>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;

/**
* SessionHandler proxy.
*
* @author Drak <drak@zikula.org>
*/
class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface
Copy link
Contributor Author

@afurculita afurculita Sep 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also move this class from the Proxy folder to Handler. What do you think, @nicolas-grekas ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would need deprecating this class in favor of the new one, and allow triggering a deprecation in AbstractProxy also. LGTM.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the SessionHandlerProxy can be deprecated as well. When we only support \SessionHandlerInterface anyway, the proxy does not provide any value anymore AFAIK. I was meant as a way to make \SessionHandlerInterface and others behave the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking the same. The extra methods that SessionHandlerProxy is having can easily be moved to NativeSessionStorage as they are relevant only for a native session storage.

Expand All @@ -23,11 +21,6 @@ class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterf
*/
protected $handler;

/**
* Constructor.
*
* @param \SessionHandlerInterface $handler
*/
public function __construct(\SessionHandlerInterface $handler)
{
$this->handler = $handler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
* @group legacy
*/
class NativeSessionHandlerTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,19 @@ public function testGetSaveHandlerName()
$this->assertNull($this->proxy->getSaveHandlerName());
}

/**
* @group legacy
*/
public function testIsSessionHandlerInterface()
{
$this->assertFalse($this->proxy->isSessionHandlerInterface());
$sh = new ConcreteSessionHandlerInterfaceProxy();
$this->assertTrue($sh->isSessionHandlerInterface());
}

/**
* @group legacy
*/
public function testIsWrapper()
{
$this->assertFalse($this->proxy->isWrapper());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
/**
* Test class for NativeProxy.
*
* @group legacy
*
* @author Drak <drak@zikula.org>
*/
class NativeProxyTest extends TestCase
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.