domovoy/app/Models/Device.php

53 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Domovoy\Models;
class Device
{
public ?int $id = null;
public string $name = '';
public string $type = 'unknown';
public ?string $description = null;
public ?string $primaryIp = null;
public ?string $macAddress = null;
public ?string $hostname = null;
public ?string $vendor = null;
public ?string $osName = null;
public ?string $osVersion = null;
public ?string $location = null;
public string $importance = 'normal';
public string $status = 'active';
public ?\DateTimeImmutable $createdAt = null;
public ?\DateTimeImmutable $updatedAt = null;
public static function fromArray(array $data): self
{
$obj = new self();
$obj->id = (int)$data['id'];
$obj->name = $data['name'];
$obj->type = $data['type'];
$obj->description = $data['description'] ?? null;
$obj->primaryIp = $data['primary_ip'] ?? null;
$obj->macAddress = $data['mac_address'] ?? null;
$obj->hostname = $data['hostname'] ?? null;
$obj->vendor = $data['vendor'] ?? null;
$obj->osName = $data['os_name'] ?? null;
$obj->osVersion = $data['os_version'] ?? null;
$obj->location = $data['location'] ?? null;
$obj->importance = $data['importance'];
$obj->status = $data['status'];
$obj->createdAt = new \DateTimeImmutable($data['created_at']);
$obj->updatedAt = new \DateTimeImmutable($data['updated_at']);
return $obj;
}
public static array $types = [
'server', 'router', 'nas', 'desktop', 'laptop',
'phone', 'printer', 'iot', 'vm', 'container_host', 'unknown',
];
public static array $importances = ['critical', 'high', 'normal', 'low'];
}