Итерация 3: инвентарь устройств
- Миграция devices (name, type, ip, mac, hostname, vendor, os, location, importance, status) - Device model + DeviceRepository с полным CRUD - DeviceService для бизнес-логики - MergeSuggestionService для предложений объединения (MAC→90%, hostname→60%) - DeviceController: список, создание, редактирование, карточка, удаление, создание из discovered_host - Шаблоны: devices/index, devices/form, devices/show - Dashboard с реальными счётчиками (устройства, новые находки) - Кнопка «Создать устройство» в Discovery для новых хостов - DeviceRepository + DeviceService + DeviceController в DI
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?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'];
|
||||
}
|
||||
Reference in New Issue
Block a user