dbms/app/Controllers/Admin/Equipment/Part/LineController.php
2025-06-05 19:07:27 +09:00

67 lines
2.3 KiB
PHP

<?php
namespace App\Controllers\Admin\Equipment\Part;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Entities\Equipment\Part\LineEntity;
use App\Helpers\Equipment\Part\LineHelper;
use App\Services\Equipment\Part\LineService;
use App\Services\Equipment\Part\IpService;
use App\Entities\Equipment\Part\IpEntity;
class LineController extends PartController
{
private ?IpService $_ipService = null;
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(): LineService
{
if (!$this->_service) {
$this->_service = new LineService($this->request);
}
return $this->_service;
}
public function getHelper(): LineHelper
{
if (!$this->_helper) {
$this->_helper = new LineHelper($this->request);
}
return $this->_helper;
}
final public function getIpService(): IpService
{
if (!$this->_ipService) {
$this->_ipService = new IpService($this->request);
}
return $this->_ipService;
}
//Index,FieldForm관련
//생성
protected function create_process(string $action, array $fields, array $formDatas = []): LineEntity
{
//Line 등록
if (!$this->getHelper()->isValidCIDR($this->formDatas['bandwith'])) {
throw new \Exception("{$this->formDatas['bandwith']}는 CIDR 형식에 부합되지 않습니다.");
}
//데이터 검증
$validatedFormDatas = $this->doValidate($action, $fields, $formDatas);
return $this->getService()->create($validatedFormDatas);
//IP 등록
foreach ($this->getHelper()->cidrToIpRange($this->formDatas['bandwith']) as $ip) {
$this->getIpService()->createByLineInfo($entity, $ip);
}
return $entity;
}
}