trafficmonitor init...2

This commit is contained in:
choi.jh 2025-11-11 11:50:21 +09:00
parent b886f2dc30
commit 46955cf337
10 changed files with 57 additions and 83 deletions

View File

@ -32,28 +32,28 @@ abstract class AdminController extends CommonController
parent::action_init_process($action);
$this->addViewDatas('layout', $this->getLayout());
}
abstract protected function create_form_process(string $action): void;
abstract protected function create_form_process(): void;
final public function create_form(): string
{
$action = __FUNCTION__;
try {
//초기화
$this->action_init_process($action);
$this->create_form_process($action);
$this->create_form_process();
} catch (\Exception $e) {
log_message('error', $e->getMessage());
session()->setFlashdata('message', $e->getMessage());
}
return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas());
}
abstract protected function create_process(string $action): array;
abstract protected function create_process(): array;
final public function create(): string|RedirectResponse
{
$action = __FUNCTION__;
try {
//초기화
$this->action_init_process($action);
list($entity, $message) = $this->create_process($action);
list($entity, $message) = $this->create_process();
return $this->action_modal_process($message);
} catch (ValidationException $e) {
// 검증 실패 시 폼으로 돌아가서 오류 메시지 표시
@ -64,28 +64,28 @@ abstract class AdminController extends CommonController
return redirect()->back()->withInput()->with('message', $e->getMessage());
}
}
abstract protected function modify_form_process(string $action, $uid): void;
abstract protected function modify_form_process($uid): void;
final public function modify_form($uid): string
{
$action = __FUNCTION__;
try {
//초기화
$this->action_init_process($action);
$this->modify_form_process($action, $uid);
$this->modify_form_process($uid);
} catch (\Exception $e) {
log_message('error', $e->getMessage());
session()->setFlashdata('message', $e->getMessage());
}
return $this->action_render_process($this->getActionPaths(), $action, $this->getViewDatas());
}
abstract protected function modify_process(string $action, $uid): array;
abstract protected function modify_process($uid): array;
final public function modify($uid): string|RedirectResponse
{
$action = __FUNCTION__;
try {
//초기화
$this->action_init_process($action);
list($entity, $message) = $this->modify_process($action, $uid);
list($entity, $message) = $this->modify_process($uid);
return $this->action_modal_process($message);
} catch (ValidationException $e) {
// 검증 실패 시 폼으로 돌아가서 오류 메시지 표시
@ -157,7 +157,7 @@ abstract class AdminController extends CommonController
//Filter조건절 처리
$index_filters = [];
foreach ($this->service->getFormService()->getFormFilters($action) as $field) {
$value = $this->request->getVar($field) ?? null;
$value = $this->request->getVar(index: $field) ?? null;
if ($value) {
$this->service->setFilter($field, $value);
$index_filters[$field] = $value;

View File

@ -49,20 +49,20 @@ class CollectorController extends AdminController
$this->addViewDatas('formOptions', $this->service->getFormService()->getFormOptions($action, $filters));
}
//Action작업관련
protected function create_form_process(string $action): void
protected function create_form_process(): void
{
//Form Default값 설정
$formDatas = [];
$this->addViewDatas('formDatas', $formDatas);
}
protected function create_process(string $action): array
protected function create_process(): array
{
//요청 데이터를 DTO 객체로 변환
$dto = new CollectorDTO($this->request->getPost());
$entity = $this->service->create($dto);
return array($entity, "{$entity->getTitle()} 수집정보 생성이 완료되었습니다.");
}
protected function modify_form_process(string $action, $uid): void
protected function modify_form_process($uid): void
{
if (!$uid) {
throw new \Exception("수집정보 번호가 정의 되지 않았습니다.");
@ -73,7 +73,7 @@ class CollectorController extends AdminController
}
$this->addViewDatas('entity', $entity);
}
protected function modify_process(string $action, $uid): array
protected function modify_process($uid): array
{
//요청 데이터를 DTO 객체로 변환
$dto = new CollectorDTO($this->request->getPost());

View File

@ -49,20 +49,20 @@ class MylogController extends AdminController
$this->addViewDatas('formOptions', $this->service->getFormService()->getFormOptions($action, $filters));
}
//Action작업관련
protected function create_form_process(string $action): void
protected function create_form_process(): void
{
//Form Default값 설정
$formDatas = [];
$this->addViewDatas('formDatas', $formDatas);
}
protected function create_process(string $action): array
protected function create_process(): array
{
//요청 데이터를 DTO 객체로 변환
$dto = new MylogDTO($this->request->getPost());
$entity = $this->service->create($dto);
return array($entity, "{$entity->getTitle()} 로그 생성이 완료되었습니다.");
}
protected function modify_form_process(string $action, $uid): void
protected function modify_form_process($uid): void
{
if (!$uid) {
throw new \Exception("로그 번호가 정의 되지 않았습니다.");
@ -73,7 +73,7 @@ class MylogController extends AdminController
}
$this->addViewDatas('entity', $entity);
}
protected function modify_process(string $action, $uid): array
protected function modify_process($uid): array
{
//요청 데이터를 DTO 객체로 변환
$dto = new MylogDTO($this->request->getPost());

View File

@ -49,20 +49,20 @@ class TrafficController extends AdminController
$this->addViewDatas('formOptions', $this->service->getFormService()->getFormOptions($action, $filters));
}
//Action작업관련
protected function create_form_process(string $action): void
protected function create_form_process(): void
{
//Form Default값 설정
$formDatas = [];
$this->addViewDatas('formDatas', $formDatas);
}
protected function create_process(string $action): array
protected function create_process(): array
{
//요청 데이터를 DTO 객체로 변환
$dto = new TrafficDTO($this->request->getPost());
$entity = $this->service->create($dto);
return array($entity, "{$entity->getTitle()} 트래픽정보 생성이 완료되었습니다.");
}
protected function modify_form_process(string $action, $uid): void
protected function modify_form_process($uid): void
{
if (!$uid) {
throw new \Exception("트래픽정보 번호가 정의 되지 않았습니다.");
@ -73,7 +73,7 @@ class TrafficController extends AdminController
}
$this->addViewDatas('entity', $entity);
}
protected function modify_process(string $action, $uid): array
protected function modify_process($uid): array
{
//요청 데이터를 DTO 객체로 변환
$dto = new TrafficDTO($this->request->getPost());

View File

@ -19,15 +19,6 @@ class UserController extends AdminController
}
$this->addActionPaths($this::PATH);
}
protected function getFormRule_process(string $action, string $field, string $rule): array
{
switch ($field) {
case 'role':
$field = "{$field}.*";
break;
}
return parent::getFormRule_process($action, $field, $rule);
}
//Action작업관련
protected function action_init_process(string $action): void
{
@ -58,20 +49,20 @@ class UserController extends AdminController
$this->addViewDatas('formRules', $this->service->getFormService()->getFormRules($action, $fields));
$this->addViewDatas('formOptions', $this->service->getFormService()->getFormOptions($action, $filters));
}
protected function create_form_process(string $action): void
protected function create_form_process(): void
{
//Form Default값 설정
$formDatas = ['role' => [ROLE['USER']['MANAGER']]];
$this->addViewDatas('formDatas', $formDatas);
}
protected function create_process(string $action): array
protected function create_process(): array
{
//요청 데이터를 DTO 객체로 변환
$dto = new UserDTO($this->request->getPost());
$entity = $this->service->create($dto);
return array($entity, "{$entity->getTitle()} 계정 생성이 완료되었습니다.");
}
protected function modify_form_process(string $action, $uid): void
protected function modify_form_process($uid): void
{
if (!$uid) {
throw new \Exception("계정 번호가 정의 되지 않았습니다.");
@ -82,7 +73,7 @@ class UserController extends AdminController
}
$this->addViewDatas('entity', $entity);
}
protected function modify_process(string $action, $uid): array
protected function modify_process($uid): array
{
//요청 데이터를 DTO 객체로 변환
$dto = new UserDTO($this->request->getPost());

View File

@ -44,33 +44,8 @@ abstract class CommonController extends BaseController
return $this->_viewDatas[$key] ?? null;
}
//공통 필수기능
final protected function doValidation(string $action): array
{
$dynamicRules = [];
foreach ($this->service->getFormRules($action) as $field => $rule) {
//field별 추가 커스텀 룰 적용
list($field, $rule) = $this->getFormRule_process($action, $field, $rule);
$dynamicRules[$field] = $rule;
}
//변경할 값 확인 : Upload된 파일 검증시 $this->request->getPOST()보다 먼처 체크필요
if (!$this->validate($dynamicRules)) {
throw new \Exception(static::class . "에서 작업 데이터 검증 오류발생\n" . implode(
"\n",
$this->validator->getErrors()
));
}
return $this->validator->getValidated();
}
//필수함수
//사용자정의 함수
protected function getFormRule_process(string $action, string $field, string $rule): array
{
switch ($field) {
default:
break;
}
return array($field, $rule);
}
protected function action_init_process(string $action): void
{
$this->addViewDatas('action', $action);

View File

@ -9,7 +9,7 @@ class TrafficDTO extends CommonDTO
public ?string $switch = null;
public ?string $ip = null;
public ?string $interface = null;
public ?int $status = null;
public ?string $status = null;
public function __construct(array $datas = [])
{

View File

@ -83,21 +83,19 @@ abstract class AuthService
throw new \Exception($message);
}
}
final protected function getValidationRules(string $action, array $allRules = []): array
final protected function getValidationRules(string $action, array $rules): array
{
foreach ($this->getFormService()->getFormFields($action) as $field => $label) {
$allRules = array_merge($allRules, $this->getValidationRule($action, $field, $allRules));
$dynamicRules = [];
foreach ($rules as $field => $rule) {
//field별 추가 커스텀 룰 적용
list($field, $rule) = $this->getValidationRule($field, $rule);
$dynamicRules[$field] = $rule;
}
return $allRules;
return $dynamicRules;
}
protected function getValidationRule(string $action, string $field, array $rules = []): array
protected function getValidationRule(string $field, string $rule): array
{
switch ($field) {
default:
$rules = $this->getFormService()->getFormRule($action, $field);
break;
}
return $rules;
return array($field, $rule);
}
//로그인

View File

@ -87,21 +87,19 @@ abstract class CommonService
return $entities;
}
//Validation용
final protected function getValidationRules(string $action, array $allRules = []): array
final protected function getValidationRules(string $action, array $rules): array
{
foreach ($this->getFormService()->getFormFields($action) as $field => $label) {
$allRules = array_merge($allRules, $this->getValidationRule($action, $field, $allRules));
$dynamicRules = [];
foreach ($rules as $field => $rule) {
//field별 추가 커스텀 룰 적용
list($field, $rule) = $this->getValidationRule($field, $rule);
$dynamicRules[$field] = $rule;
}
return $allRules;
return $dynamicRules;
}
protected function getValidationRule(string $action, string $field, array $rules = []): array
protected function getValidationRule(string $field, string $rule): array
{
switch ($field) {
default:
$rules = $this->getFormService()->getFormRule($action, $field);
break;
}
return $rules;
return array($field, $rule);
}
//CURD 결과처리용
//DB 결과 처리 로직 통합 및 개선
@ -131,7 +129,7 @@ abstract class CommonService
{
$formDatas = (array)$dto;
//입력값 검증
$validation = service('validation')->setRules($this->getValidationRules(__FUNCTION__));
$validation = service('validation')->setRules($this->getValidationRules(__FUNCTION__,));
if (!$validation->run($formDatas)) {
throw new ValidationException(implode("\n", $validation->getErrors()));
}

View File

@ -45,6 +45,18 @@ class UserService extends CommonService
return $this->helperInstance;
}
//기본 기능부분
protected function getValidationRule(string $field, string $rule): array
{
switch ($field) {
case 'role':
$field = "{$field}.*";
break;
default:
return parent::getValidationRule($field, $rule);
// break;
}
return array($field, $rule);
}
protected function create_process(array $formDatas): UserEntity
{
if (isset($formDatas['confirmpassword'])) {