Skip to content

Commit 19ec483

Browse files
committed
minor #8542 Clarify comment about "Retrieving the User Object" (pathmissing, javiereguiluz)
This PR was submitted for the master branch but it was merged into the 3.3 branch instead (closes #8542). Discussion ---------- Clarify comment about "Retrieving the User Object" Commits ------- ab03594 Implement proposed changes 09c6616 Remove whitespace 08f938c Use preferred way of retrieving authenticated user 2b6d47f Break long lines 9e24a47 Clarify comment about "Retrieving the User Object"
2 parents 6747bc5 + ab03594 commit 19ec483

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

security.rst

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -999,14 +999,12 @@ look like::
999999

10001000
use Symfony\Component\Security\Core\User\UserInterface;
10011001

1002-
public function indexAction(UserInterface $user)
1002+
public function indexAction()
10031003
{
1004-
if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
1005-
throw $this->createAccessDeniedException();
1006-
}
1004+
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
10071005

1008-
// the above is a shortcut for this
1009-
$user = $this->get('security.token_storage')->getToken()->getUser();
1006+
$user = $this->getUser();
1007+
// or you can also type-hint a method argument with UserInterface: e.g. "UserInterface $user"
10101008
}
10111009

10121010
.. tip::
@@ -1015,10 +1013,8 @@ look like::
10151013
your :ref:`user provider <security-user-providers>`.
10161014

10171015
.. versionadded:: 3.2
1018-
The functionality to get the user via the method signature was introduced in
1019-
Symfony 3.2. You can still retrieve it by calling ``$this->getUser()`` if you
1020-
extend the :class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller`
1021-
class.
1016+
The ability to get the user by type-hinting an argument with UserInterface
1017+
was introduced in Symfony 3.2.
10221018

10231019
Now you can call whatever methods are on *your* User object. For example,
10241020
if your User object has a ``getFirstName()`` method, you could use that::

0 commit comments

Comments
 (0)