vendor/symfony/security-core/Authentication/Token/RememberMeToken.php line 21

  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. use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
  12. use Symfony\Component\Security\Core\User\UserInterface;
  13. /**
  14.  * Authentication Token for "Remember-Me".
  15.  *
  16.  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  17.  */
  18. class RememberMeToken extends AbstractToken
  19. {
  20.     private ?string $secret null;
  21.     /**
  22.      * @throws \InvalidArgumentException
  23.      */
  24.     public function __construct(
  25.         UserInterface $user,
  26.         private string $firewallName,
  27.     ) {
  28.         parent::__construct($user->getRoles());
  29.         if (\func_num_args() > 2) {
  30.             trigger_deprecation('symfony/security-core''7.2''The "$secret" argument of "%s()" is deprecated.'__METHOD__);
  31.             $this->secret func_get_arg(2);
  32.         }
  33.         if (!$firewallName) {
  34.             throw new InvalidArgumentException('$firewallName must not be empty.');
  35.         }
  36.         $this->setUser($user);
  37.     }
  38.     public function getFirewallName(): string
  39.     {
  40.         return $this->firewallName;
  41.     }
  42.     /**
  43.      * @deprecated since Symfony 7.2
  44.      */
  45.     public function getSecret(): string
  46.     {
  47.         trigger_deprecation('symfony/security-core''7.2''The "%s()" method is deprecated.'__METHOD__);
  48.         return $this->secret ??= base64_encode(random_bytes(8));
  49.     }
  50.     public function __serialize(): array
  51.     {
  52.         // $this->firewallName should be kept at index 1 for compatibility with payloads generated before Symfony 8
  53.         return [$this->secret$this->firewallNameparent::__serialize()];
  54.     }
  55.     public function __unserialize(array $data): void
  56.     {
  57.         [$this->secret$this->firewallName$parentData] = $data;
  58.         $parentData \is_array($parentData) ? $parentData unserialize($parentData);
  59.         parent::__unserialize($parentData);
  60.     }
  61. }