dbmsv4/app/Services/Equipment/LineService.php
2025-12-24 14:00:22 +09:00

95 lines
3.2 KiB
PHP

<?php
namespace App\Services\Equipment;
use App\DTOs\Equipment\LineDTO;
use App\Entities\Equipment\LineEntity;
use App\Forms\Equipment\LineForm;
use App\Helpers\Equipment\LineHelper;
use App\Models\Equipment\LineModel;
use App\Traits\UtilTrait;
use RuntimeException;
class LineService extends EquipmentService
{
use UtilTrait;
private $_form = null;
private $_helper = null;
public function __construct(LineModel $model)
{
parent::__construct($model);
$this->addClassPaths('Line');
}
public function getDTOClass(): string
{
return LineDTO::class;
}
public function createDTO(array $formDatas): LineDTO
{
return new LineDTO($formDatas);
}
public function getEntityClass(): string
{
return LineEntity::class;
}
public function getFormService(): LineForm
{
if ($this->_form === null) {
$this->_form = new LineForm();
$this->_form->setAttributes([
'pk_field' => $this->getPKField(),
'title_field' => $this->getTitleField(),
'table' => $this->model->getTable(),
'useAutoIncrement' => $this->model->useAutoIncrement(),
'class_path' => $this->getClassPaths(false)
]);
}
return $this->_form;
}
public function getHelper(): LineHelper
{
if ($this->_helper === null) {
$this->_helper = new LineHelper();
$this->_helper->setAttributes([
'pk_field' => $this->getPKField(),
'title_field' => $this->getTitleField(),
'table' => $this->model->getTable(),
'useAutoIncrement' => $this->model->useAutoIncrement(),
'class_path' => $this->getClassPaths(false)
]);
}
return $this->_helper;
}
//기본 기능부분
protected function getEntity_process(mixed $entity): LineEntity
{
return $entity;
}
protected function create_process(array $formDatas): LineEntity
{
if (!$this->isValidCIDRTrait($formDatas['bandwith'])) {
throw new \Exception("{$formDatas['bandwith']}는 CIDR 형식에 부합되지 않습니다.");
}
//Line 등록
$entity = parent::create_process($formDatas);
if (!$entity instanceof LineEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 LineEntity만 가능");
}
//자동추가용
// 1. 기존 설정값 저장 (나중에 복구하기 위함)
$originalTime = ini_get('max_execution_time');
// 2. 이 함수를 위해 시간 늘리기 (예: 5분)
set_time_limit(300);
//IP등록
foreach ($this->cidrToIpRangeTrait($entity->getBandwith()) as $ip) {
service('part_ipservice')->attachToLine($entity, $ip);
}
// 3. 작업 완료 후 기존 설정으로 복구 (선택 사항)
set_time_limit($originalTime);
return $entity;
}
//List 검색용
//FormFilter 조건절 처리
//검색어조건절처리
}