mince/src/AuthorisationInfo.php
2024-02-21 16:08:45 +00:00

86 lines
2.1 KiB
PHP

<?php
namespace Mince;
use Index\DateTime;
use Index\Data\IDbResult;
use Index\Net\IPAddress;
use Ramsey\Uuid\{Uuid,UuidInterface};
class AuthorisationInfo {
public function __construct(
private string $id,
private string $uuid,
private string $addr,
private int $requested,
private ?int $granted,
private ?int $used,
) {}
public static function fromResult(IDbResult $result): self {
return new AuthorisationInfo(
id: $result->getString(0),
uuid: $result->getString(1),
addr: $result->getString(2),
requested: $result->getInteger(3),
granted: $result->getIntegerOrNull(4),
used: $result->getIntegerOrNull(5),
);
}
public function getId(): string {
return $this->id;
}
public function getUUIDRaw(): string {
return $this->uuid;
}
public function getUUID(): UuidInterface {
return Uuid::fromBytes($this->uuid);
}
public function getAddressRaw(): string {
return $this->addr;
}
public function getAddress(): IPAddress {
return IPAddress::parse($this->addr);
}
public function getRequestedTime(): int {
return $this->requested;
}
public function getRequestedAt(): DateTime {
return DateTime::fromUnixTimeSeconds($this->requested);
}
public function isPending(): bool {
return $this->granted === null;
}
public function isGranted(): bool {
return $this->granted !== null;
}
public function getGrantedTime(): ?int {
return $this->granted;
}
public function getGrantedAt(): ?DateTime {
return $this->granted === null ? null : DateTime::fromUnixTimeSeconds($this->granted);
}
public function isUsed(): bool {
return $this->used !== null;
}
public function getLastUsedTime(): ?int {
return $this->used;
}
public function getLastUsedAt(): ?DateTime {
return $this->used === null ? null : DateTime::fromUnixTimeSeconds($this->used);
}
}