domovoy/app/Models/DiscoveredHost.php

52 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Domovoy\Models;
class DiscoveredHost
{
public ?int $id = null;
public ?int $scanJobId = null;
public string $ipAddress = '';
public ?string $macAddress = null;
public ?string $hostname = null;
public ?string $vendor = null;
public ?string $detectedOs = null;
/** @var int[] */
public array $openPorts = [];
/** @var string[] */
public array $protocols = [];
public array $fingerprint = [];
public int $confidence = 50;
public string $status = 'new';
public ?string $matchedDeviceId = null;
public ?\DateTimeImmutable $firstSeen = null;
public ?\DateTimeImmutable $lastSeen = null;
public ?\DateTimeImmutable $createdAt = null;
public ?\DateTimeImmutable $updatedAt = null;
public static function fromArray(array $data): self
{
$obj = new self();
$obj->id = (int)$data['id'];
$obj->scanJobId = $data['scan_job_id'] !== null ? (int)$data['scan_job_id'] : null;
$obj->ipAddress = $data['ip_address'];
$obj->macAddress = $data['mac_address'] ?? null;
$obj->hostname = $data['hostname'] ?? null;
$obj->vendor = $data['vendor'] ?? null;
$obj->detectedOs = $data['detected_os'] ?? null;
$obj->openPorts = json_decode($data['open_ports_json'] ?? '[]', true);
$obj->protocols = json_decode($data['protocols_json'] ?? '[]', true);
$obj->fingerprint = json_decode($data['fingerprint_json'] ?? '{}', true);
$obj->confidence = (int)$data['confidence'];
$obj->status = $data['status'];
$obj->matchedDeviceId = $data['matched_device_id'] ?? null;
$obj->firstSeen = new \DateTimeImmutable($data['first_seen']);
$obj->lastSeen = new \DateTimeImmutable($data['last_seen']);
$obj->createdAt = new \DateTimeImmutable($data['created_at']);
$obj->updatedAt = new \DateTimeImmutable($data['updated_at']);
return $obj;
}
}