domovoy/app/Services/Inventory/DeviceService.php

60 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Domovoy\Services\Inventory;
use Domovoy\Models\Device;
use Domovoy\Repositories\DeviceRepository;
class DeviceService
{
private DeviceRepository $deviceRepository;
public function __construct(DeviceRepository $deviceRepository)
{
$this->deviceRepository = $deviceRepository;
}
public function createFromDiscoveredHost(
string $name,
string $ipAddress,
?string $macAddress = null,
?string $hostname = null,
?string $vendor = null
): Device {
$device = new Device();
$device->name = $name;
$device->primaryIp = $ipAddress;
$device->macAddress = $macAddress;
$device->hostname = $hostname;
$device->vendor = $vendor;
$device->type = 'unknown';
$device->status = 'active';
$device->importance = 'normal';
$this->deviceRepository->save($device);
return $device;
}
public function getAllDevices(): array
{
return $this->deviceRepository->findAll();
}
public function getDevice(int $id): ?Device
{
return $this->deviceRepository->findById($id);
}
public function updateDevice(Device $device): void
{
$this->deviceRepository->save($device);
}
public function deleteDevice(int $id): void
{
$this->deviceRepository->delete($id);
}
}