diff --git a/app/Controllers/Admin/AdminController.php b/app/Controllers/Admin/AdminController.php index eea222f..ca54d69 100644 --- a/app/Controllers/Admin/AdminController.php +++ b/app/Controllers/Admin/AdminController.php @@ -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; diff --git a/app/Controllers/Admin/CollectorController.php b/app/Controllers/Admin/CollectorController.php index 1a75103..6d9a1a3 100644 --- a/app/Controllers/Admin/CollectorController.php +++ b/app/Controllers/Admin/CollectorController.php @@ -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()); diff --git a/app/Controllers/Admin/MylogController.php b/app/Controllers/Admin/MylogController.php index 1fdcd3e..113eab4 100644 --- a/app/Controllers/Admin/MylogController.php +++ b/app/Controllers/Admin/MylogController.php @@ -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()); diff --git a/app/Controllers/Admin/TrafficController.php b/app/Controllers/Admin/TrafficController.php index bc90517..b812537 100644 --- a/app/Controllers/Admin/TrafficController.php +++ b/app/Controllers/Admin/TrafficController.php @@ -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()); diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index 4205904..9ab406c 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -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()); diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index 2412f6f..a1e5e7d 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -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); diff --git a/app/DTOs/TrafficDTO.php b/app/DTOs/TrafficDTO.php index d453cec..855b04c 100644 --- a/app/DTOs/TrafficDTO.php +++ b/app/DTOs/TrafficDTO.php @@ -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 = []) { diff --git a/app/Services/Auth/AuthService.php b/app/Services/Auth/AuthService.php index e7d7f98..adbc947 100644 --- a/app/Services/Auth/AuthService.php +++ b/app/Services/Auth/AuthService.php @@ -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); } //로그인 diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index 2768fbf..caf6f27 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -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())); } diff --git a/app/Services/UserService.php b/app/Services/UserService.php index a76f3b3..f0b4d90 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -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'])) {