vendor/symfony/security-core/Authentication/Token/Storage/TokenStorage.php line 33

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Security\Core\Authentication\Token\Storage;
  11. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  12. use Symfony\Contracts\Service\ResetInterface;
  13. /**
  14.  * TokenStorage contains a TokenInterface.
  15.  *
  16.  * It gives access to the token representing the current user authentication.
  17.  *
  18.  * @author Fabien Potencier <fabien@symfony.com>
  19.  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  20.  */
  21. class TokenStorage implements TokenStorageInterfaceResetInterface
  22. {
  23.     private $token;
  24.     private $initializer;
  25.     /**
  26.      * {@inheritdoc}
  27.      */
  28.     public function getToken()
  29.     {
  30.         if ($initializer $this->initializer) {
  31.             $this->initializer null;
  32.             $initializer();
  33.         }
  34.         return $this->token;
  35.     }
  36.     /**
  37.      * {@inheritdoc}
  38.      */
  39.     public function setToken(TokenInterface $token null)
  40.     {
  41.         if (null !== $token && !method_exists($token'getRoleNames') && !$token instanceof \PHPUnit\Framework\MockObject\MockObject && !$token instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
  42.             @trigger_error(sprintf('Not implementing the "%s::getRoleNames()" method in "%s" is deprecated since Symfony 4.3.'TokenInterface::class, \get_class($token)), E_USER_DEPRECATED);
  43.         }
  44.         if ($token) {
  45.             // ensure any initializer is called
  46.             $this->getToken();
  47.         }
  48.         $this->initializer null;
  49.         $this->token $token;
  50.     }
  51.     public function setInitializer(?callable $initializer): void
  52.     {
  53.         $this->initializer $initializer;
  54.     }
  55.     public function reset()
  56.     {
  57.         $this->setToken(null);
  58.     }
  59. }