Skip to content

Commit

Permalink
Symfony 5.3 deprecates $token->getUsername()
Browse files Browse the repository at this point in the history
- use new `$token->getUserIdentifier()` if the function exists
- check if the token is a `NullToken` as well as null
  • Loading branch information
roverwolf authored and othillo committed Jun 4, 2021
1 parent 124ac30 commit 7493184
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Context/UserContextFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Qandidate\Toggle\Context;
use Qandidate\Toggle\ContextFactory;
use Symfony\Component\Security\Core\Authentication\Token\NullToken;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

class UserContextFactory extends ContextFactory
Expand All @@ -35,8 +36,8 @@ public function createContext(): Context

$token = $this->tokenStorage->getToken();

if (null !== $token) {
$context->set('username', $token->getUsername());
if (null !== $token && !$token instanceof NullToken) {
$context->set('username', method_exists($token, 'getUserIdentifier') ? $token->getUserIdentifier() : $token->getUsername());
}

return $context;
Expand Down

0 comments on commit 7493184

Please sign in to comment.