dbms/app/Controllers/Admin/Equipment/ServerController.php
2025-05-27 11:12:42 +09:00

114 lines
4.2 KiB
PHP

<?php
namespace App\Controllers\Admin\Equipment;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Helpers\Equipment\ServerHelper;
use App\Services\Equipment\ServerService;
use App\Services\Equipment\Link\CpuService;
use App\Services\Equipment\Link\RamService;
use App\Services\Equipment\Link\DiskService;
use App\Services\Equipment\Link\LINEService;
use App\Services\Equipment\Link\IpService;
use App\Services\Equipment\Link\DefenceService;
use App\Services\Equipment\Link\SoftwareService;
use App\Services\Equipment\Link\DomainService;
class ServerController extends EquipmentController
{
private $_adapterService = [];
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->title = lang("{$this->getService()->getClassName()}.title");
$this->class_path .= $this->getService()->getClassName();
$this->uri_path .= strtolower($this->getService()->getClassName('/')) . '/';
// $this->view_path .= strtolower($this->getService()->getClassName()) . DIRECTORY_SEPARATOR;
}
public function getService(): ServerService
{
if (!$this->_service) {
$this->_service = new ServerService($this->request);
}
return $this->_service;
}
public function getHelper(): ServerHelper
{
if (!$this->_helper) {
$this->_helper = new ServerHelper($this->request);
}
return $this->_helper;
}
final public function getAdapterService(string $key): mixed
{
if (!array_key_exists($key, $this->_adapterService)) {
switch ($key) {
case 'CPU':
$this->_adapterService[$key] = new CpuService();
break;
case 'RAM':
$this->_adapterService[$key] = new RamService();
break;
case 'DISK':
$this->_adapterService[$key] = new DiskService();
break;
case 'LINE':
$this->_adapterService[$key] = new LineService();
break;
case 'IP':
$this->_adapterService[$key] = new IpService();
break;
case 'DEFENCE':
$this->_adapterService[$key] = new DefenceService();
break;
case 'SOFTWARE':
$this->_adapterService[$key] = new SoftwareService();
break;
case 'DOMAIN':
$this->_adapterService[$key] = new DomainService();
break;
default:
throw new \Exception("Unknown adapter service key: {$key}");
}
}
return $this->_adapterService[$key];
}
protected function getResultPageByActon(string $action, string $message = MESSAGES["SUCCESS"]): RedirectResponse|string
{
switch ($action) {
case 'index':
$this->getHelper()->setViewDatas($this->getViewDatas());
$result = view($this->view_path . 'server' . DIRECTORY_SEPARATOR . $action, ['viewDatas' => $this->getViewDatas()]);
break;
default:
$result = parent::getResultPageByActon($action, $message);
break;
}
return $result;
}
//Index,FieldForm관련
protected function index_process(): array
{
$fields = [
'fields' => ['code', 'type', 'model', 'price', "raid", 'status'],
];
$this->init('index', $fields);
// $this->modal_type = 'modal_fetch_v2'; //기본은 modal_iframe임
$this->adapterFields = ['LINE', 'IP', 'CPU', 'RAM', 'DISK', 'DEFENCE', 'SOFTWARE', 'DOMAIN'];
$entities = [];
foreach (parent::index_process() as $entity) {
foreach ($this->adapterFields as $field) {
$entity->setPartEntities($field, $this->getAdapterService($field)->getAdapterEntities($entity));
}
$entities[] = $entity;
}
return $entities;
}
}