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

  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 ?TokenInterface $token null;
  24.     private ?\Closure $initializer null;
  25.     public function getToken(): ?TokenInterface
  26.     {
  27.         if ($initializer $this->initializer) {
  28.             $this->initializer null;
  29.             $initializer();
  30.         }
  31.         return $this->token;
  32.     }
  33.     public function setToken(TokenInterface $token null)
  34.     {
  35.         if (\func_num_args()) {
  36.             trigger_deprecation('symfony/security-core''6.2''Calling "%s()" without any arguments is deprecated, pass null explicitly instead.'__METHOD__);
  37.         }
  38.         if ($token) {
  39.             // ensure any initializer is called
  40.             $this->getToken();
  41.         }
  42.         $this->initializer null;
  43.         $this->token $token;
  44.     }
  45.     public function setInitializer(?callable $initializer): void
  46.     {
  47.         $this->initializer null === $initializer null $initializer(...);
  48.     }
  49.     public function reset()
  50.     {
  51.         $this->setToken(null);
  52.     }
  53. }