You've already forked wc-licensed-product-client
54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Magdev\WcLicensedProductClient\Dto;
|
||
|
|
|
||
|
|
enum LicenseState: string
|
||
|
|
{
|
||
|
|
case Active = 'active';
|
||
|
|
case Inactive = 'inactive';
|
||
|
|
case Expired = 'expired';
|
||
|
|
case Revoked = 'revoked';
|
||
|
|
}
|
||
|
|
|
||
|
|
final readonly class LicenseStatus
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
public bool $valid,
|
||
|
|
public LicenseState $status,
|
||
|
|
public string $domain,
|
||
|
|
public ?\DateTimeImmutable $expiresAt,
|
||
|
|
public int $activationsCount,
|
||
|
|
public int $maxActivations,
|
||
|
|
) {
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function fromArray(array $data): self
|
||
|
|
{
|
||
|
|
$expiresAt = null;
|
||
|
|
if (isset($data['expires_at']) && $data['expires_at'] !== null) {
|
||
|
|
$expiresAt = new \DateTimeImmutable($data['expires_at']);
|
||
|
|
}
|
||
|
|
|
||
|
|
return new self(
|
||
|
|
valid: $data['valid'],
|
||
|
|
status: LicenseState::from($data['status']),
|
||
|
|
domain: $data['domain'],
|
||
|
|
expiresAt: $expiresAt,
|
||
|
|
activationsCount: $data['activations_count'],
|
||
|
|
maxActivations: $data['max_activations'],
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function isLifetime(): bool
|
||
|
|
{
|
||
|
|
return $this->expiresAt === null;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function hasAvailableActivations(): bool
|
||
|
|
{
|
||
|
|
return $this->activationsCount < $this->maxActivations;
|
||
|
|
}
|
||
|
|
}
|