48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\DomainFluctuation\App\DTOs;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class DomainFluctuationTermDTO
|
|
{
|
|
public function __construct(
|
|
public readonly string $termName,
|
|
public readonly string $description,
|
|
public readonly int $dateCreate,
|
|
public readonly int $userId,
|
|
public readonly bool $status = false,
|
|
public readonly string $type = 'vnnic_06',
|
|
) {}
|
|
|
|
public static function fromArray(array $data): self
|
|
{
|
|
$dateCreate = $data['date_create'] ?? null;
|
|
if ($dateCreate === null) {
|
|
$dateCreate = time();
|
|
} elseif (! is_int($dateCreate) && ! ctype_digit((string) $dateCreate)) {
|
|
$dateCreate = Carbon::parse($dateCreate)->timestamp;
|
|
}
|
|
|
|
return new self(
|
|
termName: $data['term_name'],
|
|
description: $data['description'] ?? '',
|
|
dateCreate: (int) $dateCreate,
|
|
userId: (int) $data['user_id'],
|
|
status: (bool) ($data['status'] ?? false),
|
|
type: $data['type'] ?? 'vnnic_06',
|
|
);
|
|
}
|
|
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'term_name' => $this->termName,
|
|
'description' => $this->description,
|
|
'date_create' => $this->dateCreate,
|
|
'user_id' => $this->userId,
|
|
'status' => $this->status,
|
|
];
|
|
}
|
|
}
|