diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index 2b212c3..16554db 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -35,17 +35,18 @@ class UserController extends AdminController } return $this->service; } - protected function setValidation(string $action, string $field): void + protected function setValidation(string $action, string $field, Validation $validation): Validation { switch ($field) { case 'role': //아래 Rule Array는 필드명.* checkbox를 사용 - $this->_validation->setRule("{$field}.*", $field, $this->getModel()->getFieldRule($action, $field)); + $validation->setRule("{$field}.*", $field, $this->getModel()->getFieldRule($action, $field)); break; default: - parent::setValidation($action, $field); + $validation = parent::setValidation($action, $field, $validation); break; } + return $validation; } private function init(string $action, array $fields = []): void { diff --git a/app/Controllers/MVController.php b/app/Controllers/MVController.php index de6e153..85b05ec 100644 --- a/app/Controllers/MVController.php +++ b/app/Controllers/MVController.php @@ -14,7 +14,6 @@ use Psr\Log\LoggerInterface; abstract class MVController extends CommonController { - protected $_validation = null; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); @@ -23,20 +22,22 @@ abstract class MVController extends CommonController abstract protected function getModel(): mixed; abstract protected function getService(): mixed; //Field별 Form Rule용 - protected function setValidation(string $action, string $field): void + protected function setValidation(string $action, string $field, Validation $validation): Validation { switch ($field) { default: - $this->_validation->setRule($field, $field, $this->getModel()->getFieldRule($action, $field)); + $validation->setRule($field, $field, $this->getModel()->getFieldRule($action, $field)); break; } + return $validation; } - final protected function setValidations(string $action, array $fields): void + final protected function getValidation(string $action, array $fields): Validation { - $this->_validation = service('validation'); + $validation = service('validation'); foreach ($fields as $field) { - $this->setValidation($action, $field); + $validation = $this->setValidation($action, $field, $validation); } + return $validation; } //Field별 Form Option용 protected function getFormFieldOption(string $field, array $options): array @@ -80,14 +81,14 @@ abstract class MVController extends CommonController protected function create_validate(string $action, array $fields): array { //변경할 값 확인 : Upload된 파일 검증시 $this->request->getPOST()보다 먼처 체크필요 - $this->setValidations($action, $fields); - if (!$this->_validation->withRequest($this->request)->run()) { + $validation = $this->getValidation($action, $fields); + if (!$validation->withRequest($this->request)->run()) { throw new \Exception("{$this->getService()->class_name} 작업 데이터 검증 오류발생\n" . implode( "\n", - $this->_validation->getErrors() + $validation->getErrors() )); } - return $this->_validation->getValidated(); + return $validation->getValidated(); } protected function create_process(): void { @@ -143,15 +144,14 @@ abstract class MVController extends CommonController final protected function modify_validate(string $action, array $fields): array { //변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요 - $this->setValidations($action, $fields); - if (!$this->_validation->withRequest($this->request)->run()) { + $validation = $this->getValidation($action, $fields); + if (!$validation->withRequest($this->request)->run()) { throw new \Exception("{$this->getService()->class_name} 작업 데이터 검증 오류발생\n" . implode( "\n", - $this->_validation->getErrors() + $validation->getErrors() )); } - // dd((array)$this->_validation); - return $this->_validation->getValidated(); + return $validation->getValidated(); } //modify,toggle,batchjob 공통사용 protected function modify_process(mixed $uid): void