91 lines
3.3 KiB
PHP
91 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\DTOs\TrafficDTO;
|
|
use App\Entities\TrafficEntity;
|
|
use App\Forms\TrafficForm;
|
|
use App\Helpers\TrafficHelper;
|
|
use App\Models\TrafficModel;
|
|
use RuntimeException;
|
|
|
|
class TrafficService extends CommonService
|
|
{
|
|
public function __construct(TrafficModel $model)
|
|
{
|
|
parent::__construct($model);
|
|
$this->addClassPaths('Traffic');
|
|
}
|
|
public function getFormService(): TrafficForm
|
|
{
|
|
if ($this->formServiceInstance === null) {
|
|
$this->formServiceInstance = new TrafficForm();
|
|
$this->formServiceInstance->setAttributes([
|
|
'pk_field' => $this->model->getPKField(),
|
|
'title_field' => $this->model->getTitleField(),
|
|
'table' => $this->model->getTable(),
|
|
'useAutoIncrement' => $this->model->useAutoIncrement(),
|
|
'class_path' => $this->getClassPaths(false)
|
|
]);
|
|
}
|
|
return $this->formServiceInstance;
|
|
}
|
|
public function getHelper(): TrafficHelper
|
|
{
|
|
if ($this->helperInstance === null) {
|
|
$this->helperInstance = new TrafficHelper();
|
|
$this->helperInstance->setAttributes([
|
|
'pk_field' => $this->model->getPKField(),
|
|
'title_field' => $this->model->getTitleField(),
|
|
'table' => $this->model->getTable(),
|
|
'useAutoIncrement' => $this->model->useAutoIncrement(),
|
|
'class_path' => $this->getClassPaths(false)
|
|
]);
|
|
}
|
|
return $this->helperInstance;
|
|
}
|
|
//기본 기능부분
|
|
protected function create_process(array $formDatas): TrafficEntity
|
|
{
|
|
//TrafficEntity를 생성하면 Setter가 자동 호출됩니다.
|
|
return new TrafficEntity($formDatas);
|
|
}
|
|
public function create(object $dto): TrafficEntity
|
|
{
|
|
if (!$dto instanceof TrafficDTO) {
|
|
throw new RuntimeException(__METHOD__ . "에서 오류발생:" . get_class($dto) . "는 사용할수 없습니다.");
|
|
}
|
|
return parent::create($dto);
|
|
}
|
|
protected function modify_process($uid, array $formDatas): TrafficEntity
|
|
{
|
|
if (!$uid) {
|
|
throw new \Exception("트래픽 번호가 정의 되지 않았습니다.");
|
|
}
|
|
$entity = $this->getEntity($uid);
|
|
if (!$entity instanceof TrafficEntity) {
|
|
throw new \Exception("{$uid}에 해당하는 트래픽정보을 찾을수 없습니다.");
|
|
}
|
|
// 변경 사항을 Entity에 적용합니다. (Dirty Tracking 활성화)
|
|
$formDatas[$this->model->getPKField()] = $uid;
|
|
$entity->fill($formDatas);
|
|
// 💡 부모 호출 제거: 변경된 Entity 객체를 반환합니다.
|
|
return $entity;
|
|
}
|
|
public function modify($uid, object $dto): TrafficEntity
|
|
{
|
|
if (!$dto instanceof TrafficDTO) {
|
|
throw new RuntimeException(__METHOD__ . "에서 오류발생:" . get_class($dto) . "는 사용할수 없습니다.");
|
|
}
|
|
return parent::modify($uid, $dto);
|
|
}
|
|
//List 검색용
|
|
//FormFilter 조건절 처리
|
|
//검색어조건절처리
|
|
public function setSearchWord(string $word): void
|
|
{
|
|
$this->model->orLike($this->model->getTable() . "." . $this->model->getTitleField(), $word, 'both');
|
|
parent::setSearchWord($word);
|
|
}
|
|
}
|