-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[HttpFoundation] Deprecate Request::getSession() when Request::hasSession() is false #9625
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 2 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 |
---|---|---|
|
@@ -235,6 +235,13 @@ the | |
method tells you if the request contains a session which was started in one of | ||
the previous requests. | ||
|
||
.. versionadded:: 4.1 | ||
|
||
Using :method:`Symfony\\Component\\HttpFoundation\\Request::getSession()` when no session | ||
has been set, was deprecated in Symfony 4.1. It will throw an exception in | ||
Symfony 5.0 when session is null. | ||
Use :method:`Symfony\\Component\\HttpFoundation\\Request::hasSession()` instead. | ||
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 would this reword to say something like "Check for an existing session first by calling |
||
|
||
Accessing ``Accept-*`` Headers Data | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -444,7 +444,9 @@ remove this variable, it's better to use the | |
// ... | ||
use Symfony\Component\Security\Http\Util\TargetPathTrait; | ||
|
||
$targetPath = $this->getTargetPath($request->getSession(), $providerKey); | ||
$session = $request->hasSession() ? $request->getSession() : throw_no_session_exception(); | ||
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 am not convinced we should throw an exception here. Not having a session looks valid to me and we should then just use the empty value as the target path IMO. |
||
|
||
$targetPath = $this->getTargetPath($session, $providerKey); | ||
|
||
// equivalent to: | ||
// $targetPath = $request->getSession()->get('_security.'.$providerKey.'.target_path'); | ||
// $targetPath = $session->get('_security.'.$providerKey.'.target_path'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the blank line must be removed