domovoy/app/Models/ScanJob.php

38 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Domovoy\Models;
class ScanJob
{
public ?int $id = null;
public string $type = '';
public string $status = 'pending';
public ?int $networkRangeId = null;
public ?string $deviceId = null;
public ?\DateTimeImmutable $startedAt = null;
public ?\DateTimeImmutable $finishedAt = null;
public ?string $errorMessage = null;
public ?string $resultJson = null;
public ?string $createdBy = null;
public ?\DateTimeImmutable $createdAt = null;
public static function fromArray(array $data): self
{
$obj = new self();
$obj->id = (int)$data['id'];
$obj->type = $data['type'];
$obj->status = $data['status'];
$obj->networkRangeId = $data['network_range_id'] !== null ? (int)$data['network_range_id'] : null;
$obj->deviceId = $data['device_id'] ?? null;
$obj->startedAt = $data['started_at'] !== null ? new \DateTimeImmutable($data['started_at']) : null;
$obj->finishedAt = $data['finished_at'] !== null ? new \DateTimeImmutable($data['finished_at']) : null;
$obj->errorMessage = $data['error_message'] ?? null;
$obj->resultJson = $data['result_json'] ?? null;
$obj->createdBy = $data['created_by'] ?? null;
$obj->createdAt = new \DateTimeImmutable($data['created_at']);
return $obj;
}
}