123 lines
5.0 KiB
PHP
123 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace Modules\DomainFluctuation\App\DTOs;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class DomainFluctuationDTO
|
|
{
|
|
public function __construct(
|
|
public readonly string $domainName,
|
|
public readonly int $termId,
|
|
public readonly string $ownerName,
|
|
public readonly string $ownerType,
|
|
public readonly string $address,
|
|
public readonly string $countryCode,
|
|
public readonly string $adminName,
|
|
public readonly string $phone,
|
|
public readonly string $email,
|
|
public readonly int $registeredDate,
|
|
public readonly int $expiredDate,
|
|
public readonly ?string $wardName = null,
|
|
public readonly ?string $districtName = null,
|
|
public readonly ?string $cityName = null,
|
|
public readonly ?string $cityCode = null,
|
|
public readonly ?string $fax = null,
|
|
public readonly ?string $businessCode = null,
|
|
public readonly ?string $eidCode = null,
|
|
public readonly ?string $personalId = null,
|
|
public readonly ?string $birthDate = null,
|
|
public readonly ?string $icannRegistrarName = null,
|
|
public readonly ?string $icannRegistrarTradeName = null,
|
|
public readonly ?bool $isAgentManager = null,
|
|
public readonly ?string $action = null,
|
|
public readonly ?string $actionReason = null,
|
|
public readonly ?string $actionSource = null,
|
|
public readonly ?int $actionDate = null,
|
|
public readonly ?string $note = null,
|
|
public readonly ?int $ianaNumber = null,
|
|
public readonly ?int $status = null,
|
|
) {}
|
|
|
|
public static function fromArray(array $data): self
|
|
{
|
|
return new self(
|
|
domainName: $data['domainName'],
|
|
termId: (int) ($data['term_id'] ?? $data['termId']),
|
|
ownerName: $data['ownerName'],
|
|
ownerType: $data['ownerType'],
|
|
address: $data['address'],
|
|
countryCode: $data['countryCode'],
|
|
adminName: $data['adminName'],
|
|
phone: $data['phone'],
|
|
email: $data['email'],
|
|
registeredDate: self::toTimestamp($data['registeredDate']),
|
|
expiredDate: self::toTimestamp($data['expiredDate']),
|
|
wardName: $data['wardName'] ?? null,
|
|
districtName: $data['districtName'] ?? null,
|
|
cityName: $data['cityName'] ?? null,
|
|
cityCode: $data['cityCode'] ?? null,
|
|
fax: $data['fax'] ?? null,
|
|
businessCode: $data['businessCode'] ?? null,
|
|
eidCode: $data['eidCode'] ?? null,
|
|
personalId: $data['personalId'] ?? null,
|
|
birthDate: $data['birthDate'] ?? null,
|
|
icannRegistrarName: $data['icannRegistrarName'] ?? null,
|
|
icannRegistrarTradeName: $data['icannRegistrarTradeName'] ?? null,
|
|
isAgentManager: isset($data['isAgentManager']) ? (bool) $data['isAgentManager'] : null,
|
|
action: $data['action'] ?? null,
|
|
actionReason: $data['actionReason'] ?? null,
|
|
actionSource: $data['actionSource'] ?? null,
|
|
actionDate: isset($data['actionDate']) ? self::toTimestamp($data['actionDate']) : null,
|
|
note: $data['note'] ?? null,
|
|
ianaNumber: isset($data['ianaNumber']) ? (int) $data['ianaNumber'] : null,
|
|
status: isset($data['status']) ? (int) $data['status'] : null,
|
|
);
|
|
}
|
|
|
|
public function toArray(): array
|
|
{
|
|
return array_filter([
|
|
'domainName' => $this->domainName,
|
|
'term_id' => $this->termId,
|
|
'ownerName' => $this->ownerName,
|
|
'ownerType' => $this->ownerType,
|
|
'address' => $this->address,
|
|
'countryCode' => $this->countryCode,
|
|
'adminName' => $this->adminName,
|
|
'phone' => $this->phone,
|
|
'email' => $this->email,
|
|
'registeredDate' => $this->registeredDate,
|
|
'expiredDate' => $this->expiredDate,
|
|
'wardName' => $this->wardName,
|
|
'districtName' => $this->districtName,
|
|
'cityName' => $this->cityName,
|
|
'cityCode' => $this->cityCode,
|
|
'fax' => $this->fax,
|
|
'businessCode' => $this->businessCode,
|
|
'eidCode' => $this->eidCode,
|
|
'personalId' => $this->personalId,
|
|
'birthDate' => $this->birthDate,
|
|
'icannRegistrarName' => $this->icannRegistrarName,
|
|
'icannRegistrarTradeName' => $this->icannRegistrarTradeName,
|
|
'isAgentManager' => $this->isAgentManager,
|
|
'action' => $this->action,
|
|
'actionReason' => $this->actionReason,
|
|
'actionSource' => $this->actionSource,
|
|
'actionDate' => $this->actionDate,
|
|
'note' => $this->note,
|
|
'ianaNumber' => $this->ianaNumber,
|
|
'status' => $this->status,
|
|
], static fn ($value) => $value !== null);
|
|
}
|
|
|
|
private static function toTimestamp(int|string $value): int
|
|
{
|
|
if (is_int($value) || ctype_digit((string) $value)) {
|
|
return (int) $value;
|
|
}
|
|
|
|
return Carbon::parse($value)->timestamp;
|
|
}
|
|
}
|