<?php
namespace App\Security\Guard;
use App\Entity\Token;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken;
class ApiGuardToken extends PostAuthenticationGuardToken {
/** @var string[] */
private $rights;
/** @var Token */
private $token = NULL;
public function __construct(UserInterface $user, string $providerKey, array $roles, ?Token $token) {
parent::__construct($user, $providerKey, $roles);
$this->token = $token;
$this->rights = $token ? $token->getRights() : [];
}
public function __serialize(): array {
return [$this->rights, parent::__serialize()];
}
public function __unserialize(array $data): void {
[$this->rights, $parentData] = $data;
parent::__unserialize($parentData);
}
public function getToken(): ?Token {
return $this->token;
}
public function getRights(): array {
return $this->rights;
}
}