mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-10 01:03:13 +08:00
Feature/name api keys
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user