src/App/Security/Guard/ApiGuardToken.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Security\Guard;
  3. use App\Entity\Token;
  4. use Symfony\Component\Security\Core\User\UserInterface;
  5. use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken;
  6. class ApiGuardToken extends PostAuthenticationGuardToken {
  7.     /** @var string[] */
  8.     private $rights;
  9.     /** @var Token */
  10.     private $token NULL;
  11.     
  12.     public function __construct(UserInterface $userstring $providerKey, array $roles, ?Token $token) {
  13.         parent::__construct($user$providerKey$roles);
  14.         $this->token $token;
  15.         $this->rights $token $token->getRights() : [];
  16.     }
  17.     
  18.     public function __serialize(): array {
  19.         return [$this->rightsparent::__serialize()];
  20.     }
  21.     public function __unserialize(array $data): void {
  22.         [$this->rights$parentData] = $data;
  23.         parent::__unserialize($parentData);
  24.     }
  25.     public function getToken(): ?Token {
  26.         return $this->token;
  27.     }
  28.     public function getRights(): array {
  29.         return $this->rights;
  30.     }
  31.     
  32. }