Skip to content

Don't mention the UserInterface type-hinting #9060

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
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
11 changes: 2 additions & 9 deletions security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -994,28 +994,21 @@ shown above.
-----------------------------

After authentication, the ``User`` object of the current user can be accessed
via the ``security.token_storage`` service. From inside a controller, this will
look like::

use Symfony\Component\Security\Core\User\UserInterface;
via the ``getUser()`` shortcut (which uses the ``security.token_storage``
service). From inside a controller, this will look like::

public function indexAction()
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');

$user = $this->getUser();
// or you can also type-hint a method argument with UserInterface: e.g. "UserInterface $user"
}

.. tip::

The user will be an object and the class of that object will depend on
your :ref:`user provider <security-user-providers>`.

.. versionadded:: 3.2
The ability to get the user by type-hinting an argument with UserInterface
was introduced in Symfony 3.2.
Copy link
Contributor

@linaori linaori Jan 15, 2018

Choose a reason for hiding this comment

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


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

Expand Down