mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-10 01:03:13 +08:00
Extracted ApiKey metadata to the ApiKeyMeta object
This commit is contained in:
@@ -12,6 +12,7 @@ use Happyr\DoctrineSpecification\Spec;
|
||||
use Happyr\DoctrineSpecification\Specification\Specification;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
|
||||
use Shlinkio\Shlink\Rest\ApiKey\Model\ApiKeyMeta;
|
||||
use Shlinkio\Shlink\Rest\ApiKey\Model\RoleDefinition;
|
||||
use Shlinkio\Shlink\Rest\ApiKey\Role;
|
||||
|
||||
@@ -27,7 +28,7 @@ class ApiKey extends AbstractEntity
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct(?Chronos $expirationDate = null, ?string $name = null)
|
||||
private function __construct(?string $name = null, ?Chronos $expirationDate = null)
|
||||
{
|
||||
$this->key = Uuid::uuid4()->toString();
|
||||
$this->expirationDate = $expirationDate;
|
||||
@@ -36,30 +37,21 @@ class ApiKey extends AbstractEntity
|
||||
$this->roles = new ArrayCollection();
|
||||
}
|
||||
|
||||
public static function withRoles(RoleDefinition ...$roleDefinitions): self
|
||||
public static function create(): ApiKey
|
||||
{
|
||||
$apiKey = new self();
|
||||
return new self();
|
||||
}
|
||||
|
||||
foreach ($roleDefinitions as $roleDefinition) {
|
||||
public static function fromMeta(ApiKeyMeta $meta): self
|
||||
{
|
||||
$apiKey = new self($meta->name(), $meta->expirationDate());
|
||||
foreach ($meta->roleDefinitions() as $roleDefinition) {
|
||||
$apiKey->registerRole($roleDefinition);
|
||||
}
|
||||
|
||||
return $apiKey;
|
||||
}
|
||||
|
||||
public static function withKey(string $key, ?Chronos $expirationDate = null, ?string $name = null): self
|
||||
{
|
||||
$apiKey = new self($expirationDate, $name);
|
||||
$apiKey->key = $key;
|
||||
|
||||
return $apiKey;
|
||||
}
|
||||
|
||||
public static function withName(string $name): self
|
||||
{
|
||||
return new self(null, $name);
|
||||
}
|
||||
|
||||
public function getExpirationDate(): ?Chronos
|
||||
{
|
||||
return $this->expirationDate;
|
||||
|
||||
Reference in New Issue
Block a user