mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 17:44:44 +08:00
Extracted ApiKey metadata to the ApiKeyMeta object
This commit is contained in:
@@ -4,15 +4,57 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Rest\ApiKey\Model;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
|
||||
final class ApiKeyMeta
|
||||
{
|
||||
public static function withKey(string $key): self
|
||||
{
|
||||
private ?string $name = null;
|
||||
private ?Chronos $expirationDate = null;
|
||||
/** @var RoleDefinition[] */
|
||||
private array $roleDefinitions;
|
||||
|
||||
private function __construct(?string $name, ?Chronos $expirationDate, array $roleDefinitions)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->expirationDate = $expirationDate;
|
||||
$this->roleDefinitions = $roleDefinitions;
|
||||
}
|
||||
|
||||
public static function withName(string $key): self
|
||||
public static function withName(string $name): self
|
||||
{
|
||||
return new self($name, null, []);
|
||||
}
|
||||
|
||||
public static function withExpirationDate(Chronos $expirationDate): self
|
||||
{
|
||||
return new self(null, $expirationDate, []);
|
||||
}
|
||||
|
||||
public static function withNameAndExpirationDate(string $name, Chronos $expirationDate): self
|
||||
{
|
||||
return new self($name, $expirationDate, []);
|
||||
}
|
||||
|
||||
public static function withRoles(RoleDefinition ...$roleDefinitions): self
|
||||
{
|
||||
return new self(null, null, $roleDefinitions);
|
||||
}
|
||||
|
||||
public function name(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function expirationDate(): ?Chronos
|
||||
{
|
||||
return $this->expirationDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RoleDefinition[]
|
||||
*/
|
||||
public function roleDefinitions(): array
|
||||
{
|
||||
return $this->roleDefinitions;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user