-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle][HttpFoundation][Security] Deprecate service "session" #38616
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
namespace Symfony\Component\DependencyInjection\Loader\Configurator; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Session\DeprecatedSessionFactory; | ||
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; | ||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; | ||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; | ||
|
@@ -33,15 +34,17 @@ | |
$container->parameters()->set('session.metadata.storage_key', '_sf2_meta'); | ||
|
||
$container->services() | ||
->set('session', Session::class) | ||
->public() | ||
->set('.session.do-not-use', Session::class) // to be removed in 6.0 | ||
->args([ | ||
service('session.storage'), | ||
null, // AttributeBagInterface | ||
null, // FlashBagInterface | ||
[service('session_listener'), 'onSessionUsage'], | ||
]) | ||
->alias(SessionInterface::class, 'session') | ||
->set('.session.deprecated', SessionInterface::class) // to be removed in 6.0 | ||
->factory([inline_service(DeprecatedSessionFactory::class)->args([service('request_stack')]), 'getSession']) | ||
->alias(SessionInterface::class, '.session.do-not-use') | ||
->deprecate('symfony/framework-bundle', '5.3', 'The "%alias_id%" alias is deprecated, use "$requestStack->getSession()" instead.') | ||
->alias(SessionStorageInterface::class, 'session.storage') | ||
->alias(\SessionHandlerInterface::class, 'session.handler') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we want to remove all There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can take care of this in another PR |
||
|
||
|
@@ -65,12 +68,12 @@ | |
]) | ||
|
||
->set('session.flash_bag', FlashBag::class) | ||
jderusse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
->factory([service('session'), 'getFlashBag']) | ||
->factory([service('.session.do-not-use'), 'getFlashBag']) | ||
->deprecate('symfony/framework-bundle', '5.1', 'The "%service_id%" service is deprecated, use "$session->getFlashBag()" instead.') | ||
->alias(FlashBagInterface::class, 'session.flash_bag') | ||
|
||
->set('session.attribute_bag', AttributeBag::class) | ||
->factory([service('session'), 'getBag']) | ||
->factory([service('.session.do-not-use'), 'getBag']) | ||
->args(['attributes']) | ||
->deprecate('symfony/framework-bundle', '5.1', 'The "%service_id%" service is deprecated, use "$session->getAttributeBag()" instead.') | ||
|
||
|
@@ -94,8 +97,8 @@ | |
->set('session_listener', SessionListener::class) | ||
->args([ | ||
service_locator([ | ||
'session' => service('session')->ignoreOnInvalid(), | ||
'initialized_session' => service('session')->ignoreOnUninitialized(), | ||
'session' => service('.session.do-not-use')->ignoreOnInvalid(), | ||
jderusse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'initialized_session' => service('.session.do-not-use')->ignoreOnUninitialized(), | ||
'logger' => service('logger')->ignoreOnInvalid(), | ||
'session_collector' => service('data_collector.request.session_collector')->ignoreOnInvalid(), | ||
]), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Session; | ||
|
||
use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Component\HttpFoundation\Session\SessionInterface; | ||
|
||
/** | ||
* Provides session and trigger deprecation. | ||
* | ||
* Used by service that should trigger deprecation when accessed by the user. | ||
* | ||
* @author Jérémy Derussé <jeremy@derusse.com> | ||
* | ||
* @internal to be removed in 6.0 | ||
*/ | ||
class DeprecatedSessionFactory | ||
{ | ||
private $requestStack; | ||
|
||
public function __construct(RequestStack $requestStack) | ||
{ | ||
$this->requestStack = $requestStack; | ||
} | ||
|
||
public function getSession(): ?SessionInterface | ||
{ | ||
trigger_deprecation('symfony/framework-bundle', '5.3', 'The "session" service is deprecated, use "$requestStack->getSession()" instead.'); | ||
|
||
try { | ||
return $this->requestStack->getSession(); | ||
} catch (SessionNotFoundException $e) { | ||
return null; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class DeprecatedSessionController extends AbstractController | ||
{ | ||
public function triggerAction() | ||
{ | ||
$this->get('session'); | ||
|
||
return new Response('done'); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.