vendor/symfony/security-core/Authentication/Token/NullToken.php line 44

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;
  11. /**
  12.  * @author Wouter de Jong <wouter@wouterj.nl>
  13.  */
  14. class NullToken implements TokenInterface
  15. {
  16.     public function __toString(): string
  17.     {
  18.         return '';
  19.     }
  20.     public function getRoleNames(): array
  21.     {
  22.         return [];
  23.     }
  24.     public function getCredentials()
  25.     {
  26.         return '';
  27.     }
  28.     public function getUser()
  29.     {
  30.         return null;
  31.     }
  32.     public function setUser($user)
  33.     {
  34.         throw new \BadMethodCallException('Cannot set user on a NullToken.');
  35.     }
  36.     public function getUsername()
  37.     {
  38.         trigger_deprecation('symfony/security-core''5.3''Method "%s()" is deprecated, use getUserIdentifier() instead.'__METHOD__);
  39.         return '';
  40.     }
  41.     public function getUserIdentifier(): string
  42.     {
  43.         return '';
  44.     }
  45.     /**
  46.      * @deprecated since Symfony 5.4
  47.      */
  48.     public function isAuthenticated()
  49.     {
  50.         if (=== \func_num_args() || func_get_arg(0)) {
  51.             trigger_deprecation('symfony/security-core''5.4''Method "%s()" is deprecated, return null from "getUser()" instead when a token is not authenticated.'__METHOD__);
  52.         }
  53.         return true;
  54.     }
  55.     /**
  56.      * @deprecated since Symfony 5.4
  57.      */
  58.     public function setAuthenticated(bool $isAuthenticated)
  59.     {
  60.         throw new \BadMethodCallException('Cannot change authentication state of NullToken.');
  61.     }
  62.     public function eraseCredentials()
  63.     {
  64.     }
  65.     public function getAttributes()
  66.     {
  67.         return [];
  68.     }
  69.     public function setAttributes(array $attributes)
  70.     {
  71.         throw new \BadMethodCallException('Cannot set attributes of NullToken.');
  72.     }
  73.     public function hasAttribute(string $name)
  74.     {
  75.         return false;
  76.     }
  77.     public function getAttribute(string $name)
  78.     {
  79.         return null;
  80.     }
  81.     public function setAttribute(string $name$value)
  82.     {
  83.         throw new \BadMethodCallException('Cannot add attribute to NullToken.');
  84.     }
  85.     public function __serialize(): array
  86.     {
  87.         return [];
  88.     }
  89.     public function __unserialize(array $data): void
  90.     {
  91.     }
  92.     /**
  93.      * @return string
  94.      *
  95.      * @internal in 5.3
  96.      *
  97.      * @final in 5.3
  98.      */
  99.     public function serialize()
  100.     {
  101.         return '';
  102.     }
  103.     /**
  104.      * @return void
  105.      *
  106.      * @internal in 5.3
  107.      *
  108.      * @final in 5.3
  109.      */
  110.     public function unserialize($serialized)
  111.     {
  112.     }
  113. }