for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types = 1);
/**
* /src/Security/ApiKeyUser.php
*
* @author TLe, Tarmo Leppänen <[email protected]>
*/
namespace App\Security;
use App\Entity\ApiKey;
use App\Enum\Role;
use App\Security\Interfaces\ApiKeyUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use function array_unique;
* Class ApiKeyUser
* @package App\Security
class ApiKeyUser implements ApiKeyUserInterface, UserInterface
{
private readonly string $identifier;
private readonly string $apiKeyIdentifier;
* @var array<int, string>
private readonly array $roles;
* {@inheritdoc}
public function __construct(ApiKey $apiKey, array $roles)
$this->identifier = $apiKey->getToken();
identifier
App\Security\ApiKeyUser
$this->apiKeyIdentifier = $apiKey->getId();
apiKeyIdentifier
$this->roles = array_unique([...$roles, Role::API->value]);
roles
}
public function getUserIdentifier(): string
return $this->identifier;
public function getApiKeyIdentifier(): string
return $this->apiKeyIdentifier;
public function getRoles(): array
return $this->roles;
* @codeCoverageIgnore
public function getPassword(): ?string
return null;
public function getSalt(): ?string
public function eraseCredentials(): void