Feature/name api keys

This commit is contained in:
KetchupBomb
2021-03-06 17:27:34 +00:00
parent 65f2ab6720
commit b93b14986e
10 changed files with 163 additions and 40 deletions

View File

@@ -22,14 +22,16 @@ class ApiKey extends AbstractEntity
private bool $enabled;
/** @var Collection|ApiKeyRole[] */
private Collection $roles;
private ?string $name;
/**
* @throws Exception
*/
public function __construct(?Chronos $expirationDate = null)
public function __construct(?Chronos $expirationDate = null, ?string $name = null)
{
$this->key = Uuid::uuid4()->toString();
$this->expirationDate = $expirationDate;
$this->name = $name;
$this->enabled = true;
$this->roles = new ArrayCollection();
}
@@ -45,9 +47,9 @@ class ApiKey extends AbstractEntity
return $apiKey;
}
public static function withKey(string $key, ?Chronos $expirationDate = null): self
public static function withKey(string $key, ?Chronos $expirationDate = null, ?string $name = null): self
{
$apiKey = new self($expirationDate);
$apiKey = new self($expirationDate, $name);
$apiKey->key = $key;
return $apiKey;
@@ -63,6 +65,11 @@ class ApiKey extends AbstractEntity
return $this->expirationDate !== null && $this->expirationDate->lt(Chronos::now());
}
public function name(): ?string
{
return $this->name;
}
public function isEnabled(): bool
{
return $this->enabled;