From 86531c9ecffcec7077a14e03462890663bf090df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Wed, 2 Oct 2024 20:39:02 +0900 Subject: [PATCH] cfmgrv4 init...1 --- app/Config/Routes.php | 1 - .../Admin/Cloudflare/AccountController.php | 27 +++----- .../Admin/Cloudflare/AuthController.php | 34 +++------- .../Admin/Cloudflare/CloudflareController.php | 21 ++++++ .../Admin/Cloudflare/ZoneController.php | 28 +++----- app/Controllers/Admin/MapurlController.php | 6 -- app/Controllers/Admin/UserController.php | 68 ++++++++++++------- app/Controllers/MVController.php | 10 ++- app/Helpers/Admin/User_helper.php | 8 --- app/Models/Cloudflare/AccountModel.php | 12 ++-- app/Models/Cloudflare/AuthModel.php | 16 ++--- app/Models/Cloudflare/RecordModel.php | 16 ++--- app/Models/Cloudflare/ZoneModel.php | 14 ++-- app/Models/CommonModel.php | 31 ++++----- app/Models/MapurlModel.php | 12 ++-- app/Models/SNSUserModel.php | 12 ++-- app/Models/UserModel.php | 21 ++---- 17 files changed, 162 insertions(+), 175 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 4a0e38e..40cd083 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -24,7 +24,6 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin'], function ($rou $routes->get('delete/(:num)', 'UserController::delete/$1'); $routes->get('toggle/(:num)/(:alpha)', 'UserController::toggle/$1/$2'); $routes->post('batchjob', 'UserController::batcjob'); - $routes->get('roles/(:num)', 'UserController::roles/$1'); $routes->get('download/(:alpha)', 'UserController::download/$1'); $routes->get('download/(:alpha)/(:any)', 'UserController::download/$1/$2'); }); diff --git a/app/Controllers/Admin/Cloudflare/AccountController.php b/app/Controllers/Admin/Cloudflare/AccountController.php index e312c4b..e205e61 100644 --- a/app/Controllers/Admin/Cloudflare/AccountController.php +++ b/app/Controllers/Admin/Cloudflare/AccountController.php @@ -63,25 +63,16 @@ class AccountController extends CloudflareController $this->batchjob_fields = ['typep', 'status']; return $this->list_procedure(); } - public function reload(): RedirectResponse + //Zone Reload By Account + protected function reload_process(): void { - //Transaction Start - $this->getModel()->transStart(); - try { - foreach ($this->getModel()->getEntitys as $entity) { - $zone_socket = new ZoneSocket($entity); - $zone_socket->reload(); - } - log_message("notice", __FUNCTION__ . "=> 작업을 완료하였습니다."); - $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " => 작업을 완료하였습니다.\n"); - $this->getModel()->transCommit(); - return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); - } catch (\Exception $e) { - //Transaction Rollback - $this->getModel()->transRollback(); - log_message("error", $e->getMessage()); - $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage()); - return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); + foreach ($this->getModel()->getEntitys as $entity) { + $zone_socket = new ZoneSocket($entity); + $zone_socket->reload(); } } + public function reload(): RedirectResponse + { + return $this->reload_procedure(); + } } diff --git a/app/Controllers/Admin/Cloudflare/AuthController.php b/app/Controllers/Admin/Cloudflare/AuthController.php index 5e5fba9..2b1ebf9 100644 --- a/app/Controllers/Admin/Cloudflare/AuthController.php +++ b/app/Controllers/Admin/Cloudflare/AuthController.php @@ -44,8 +44,6 @@ class AuthController extends CloudflareController public function create(): RedirectResponse { $this->init(__FUNCTION__); - $this->create_validate($this->action, $this->fields); - $this->formDatas = $this->getFormDatas(); return $this->create_procedure(); } //수정 @@ -57,8 +55,6 @@ class AuthController extends CloudflareController public function modify(string $uid): RedirectResponse { $this->init(__FUNCTION__); - $this->modify_validate($this->action, $this->fields); - $this->formDatas = $this->getFormDatas(); return $this->modify_procedure($uid); } //일괄처리작업 @@ -67,8 +63,6 @@ class AuthController extends CloudflareController $this->action = __FUNCTION__; $this->fields = ['status']; $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->modify_validate($this->action, $this->fields); - $this->formDatas = $this->getFormDatas(); return $this->batcjob_procedure(); } // 리스트 @@ -82,26 +76,16 @@ class AuthController extends CloudflareController $this->batchjob_fields = ['status']; return $this->list_procedure(); } - - public function reload(): RedirectResponse + //Account Reload by Auth + protected function reload_process(): void { - //Transaction Start - $this->getModel()->transStart(); - try { - foreach ($this->getModel()->getEntitys as $entity) { - $account_socket = new AccountSocket($entity); - $account_socket->reload(); - } - log_message("notice", __FUNCTION__ . "=> 작업을 완료하였습니다."); - $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " => 작업을 완료하였습니다.\n"); - $this->getModel()->transCommit(); - return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); - } catch (\Exception $e) { - //Transaction Rollback - $this->getModel()->transRollback(); - log_message("error", $e->getMessage()); - $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage()); - return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); + foreach ($this->getModel()->getEntitys as $entity) { + $account_socket = new AccountSocket($entity); + $account_socket->reload(); } } + public function reload(): RedirectResponse + { + return $this->reload_procedure(); + } } diff --git a/app/Controllers/Admin/Cloudflare/CloudflareController.php b/app/Controllers/Admin/Cloudflare/CloudflareController.php index 52a959a..836ad42 100644 --- a/app/Controllers/Admin/Cloudflare/CloudflareController.php +++ b/app/Controllers/Admin/Cloudflare/CloudflareController.php @@ -5,6 +5,7 @@ namespace App\Controllers\Admin\Cloudflare; use Psr\Log\LoggerInterface; use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\RequestInterface; +use CodeIgniter\HTTP\RedirectResponse; use App\Models\Cloudflare\ZoneModel; use App\Models\Cloudflare\RecordModel; use App\Models\Cloudflare\AuthModel; @@ -51,4 +52,24 @@ abstract class CloudflareController extends AdminController } return $this->_recordModel; } + + protected function reload_process(): void {} + final protected function reload_procedure(): RedirectResponse + { + //Transaction Start + $this->getModel()->transStart(); + try { + $this->reload_process(); + log_message("notice", __FUNCTION__ . "=> 작업을 완료하였습니다."); + $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " => 작업을 완료하였습니다.\n"); + $this->getModel()->transCommit(); + return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); + } catch (\Exception $e) { + //Transaction Rollback + $this->getModel()->transRollback(); + log_message("error", $e->getMessage()); + $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage()); + return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); + } + } } diff --git a/app/Controllers/Admin/Cloudflare/ZoneController.php b/app/Controllers/Admin/Cloudflare/ZoneController.php index db70730..ccfc155 100644 --- a/app/Controllers/Admin/Cloudflare/ZoneController.php +++ b/app/Controllers/Admin/Cloudflare/ZoneController.php @@ -201,26 +201,16 @@ class ZoneController extends CloudflareController $this->batchjob_fields = ['development_mode', 'ipv6', 'security_level']; return $this->list_procedure(); } - //reload - public function reload(): RedirectResponse + //reload Record By Zone + protected function reload_process(): void { - //Transaction Start - $this->getModel()->transStart(); - try { - foreach ($this->getModel()->getEntitys as $entity) { - $record_socket = new RecordSocket($entity); - $record_socket->reload(); - } - log_message("notice", __FUNCTION__ . "=> 작업을 완료하였습니다."); - $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " => 작업을 완료하였습니다.\n"); - $this->getModel()->transCommit(); - return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); - } catch (\Exception $e) { - //Transaction Rollback - $this->getModel()->transRollback(); - log_message("error", $e->getMessage()); - $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage()); - return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); + foreach ($this->getModel()->getEntitys as $entity) { + $record_socket = new RecordSocket($entity); + $record_socket->reload(); } } + public function reload(): RedirectResponse + { + return $this->reload_procedure(); + } } diff --git a/app/Controllers/Admin/MapurlController.php b/app/Controllers/Admin/MapurlController.php index 1b4ef00..c785d17 100644 --- a/app/Controllers/Admin/MapurlController.php +++ b/app/Controllers/Admin/MapurlController.php @@ -95,8 +95,6 @@ class MapurlController extends AdminController public function create(): RedirectResponse { $this->init(__FUNCTION__); - $this->create_validate($this->action, $this->fields); - $this->formDatas = $this->getFormDatas(); return $this->create_procedure(); } //수정 @@ -114,8 +112,6 @@ class MapurlController extends AdminController public function modify(string $uid): RedirectResponse { $this->init(__FUNCTION__); - $this->modify_validate($this->action, $this->fields); - $this->formDatas = $this->getFormDatas(); return $this->modify_procedure($uid); } //일괄처리작업 @@ -124,8 +120,6 @@ class MapurlController extends AdminController $this->action = __FUNCTION__; $this->fields = ['status']; $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->modify_validate($this->action, $this->fields); - $this->formDatas = $this->getFormDatas(); return $this->batcjob_procedure(); } //삭제 diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index 876d3e8..d51eef7 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -41,18 +41,11 @@ class UserController extends AdminController { switch ($field) { case 'role': - $roles = $this->request->getVar($field . "[]"); - if (!count($roles)) { - throw new \Exception("권한이 지정되지 않았습니다."); - } - $formDatas[$field] = implode(DEFAULTS["DELIMITER_ROLE"],); - break; - case 'roles[]': $roles = $this->request->getVar($field); if (!count($roles)) { throw new \Exception("권한이 지정되지 않았습니다."); } - $formDatas['role'] = implode(DEFAULTS["DELIMITER_ROLE"],); + $formDatas[$field] = implode(DEFAULTS["DELIMITER_ROLE"],); break; default: $formDatas = parent::getFormData($field, $formDatas); @@ -69,6 +62,28 @@ class UserController extends AdminController $this->field_options = $this->getFormFieldOptions($this->filter_fields); } //생성 + protected function create_validate(string $action, array $fields): void + { + //변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요 + $this->validation = service('validation'); + foreach ($fields as $field) { + switch ($field) { + case 'role': + //아래 Rule Array는 필드명.* checkbox를 사용 + $this->validation->setRule($field . "*", $field, $this->getModel()->getRule($action, $field)); + break; + default: + $this->validation->setRule($field, $field, $this->getModel()->getRule($action, $field)); + break; + } + } + if (!$this->validation->withRequest($this->request)->run()) { + throw new \Exception("{$this->class_name} 작업 데이터 검증 오류발생\n" . implode( + "\n", + $this->validation->getErrors() + )); + } + } public function create_form(): RedirectResponse|string { $this->init('create'); @@ -77,11 +92,31 @@ class UserController extends AdminController public function create(): RedirectResponse { $this->init(__FUNCTION__); - $this->create_validate($this->action, $this->fields); - $this->formDatas = $this->getFormDatas(); return $this->create_procedure(); } //수정 + protected function modify_validate(string $action, array $fields): void + { + //변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요 + $this->validation = service('validation'); + foreach ($fields as $field) { + switch ($field) { + case 'role': + //아래 Rule Array는 필드명.* checkbox를 사용 + $this->validation->setRule($field . "*", $field, $this->getModel()->getRule($action, $field)); + break; + default: + $this->validation->setRule($field, $field, $this->getModel()->getRule($action, $field)); + break; + } + } + if (!$this->validation->withRequest($this->request)->run()) { + throw new \Exception("{$this->class_name} 작업 데이터 검증 오류발생\n" . implode( + "\n", + $this->validation->getErrors() + )); + } + } public function modify_form(string $uid): RedirectResponse|string { $this->init('modify'); @@ -90,8 +125,6 @@ class UserController extends AdminController public function modify(string $uid): RedirectResponse { $this->init(__FUNCTION__); - $this->modify_validate($this->action, $this->fields); - $this->formDatas = $this->getFormDatas(); return $this->modify_procedure($uid); } //일괄작업 @@ -100,19 +133,8 @@ class UserController extends AdminController $this->action = __FUNCTION__; $this->fields = ['status']; $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); - $this->modify_validate($this->action, $this->fields); - $this->formDatas = $this->getFormDatas(); return $this->batcjob_procedure(); } - //Role변경작업 - public function roles(string $uid): RedirectResponse - { - $this->action = __FUNCTION__; - $this->fields = ["roles[]"]; - $this->modify_validate($this->action, $this->fields); - $this->formDatas = $this->getFormDatas(); - return $this->modify_procedure($uid); - } // 리스트 public function index(): string { diff --git a/app/Controllers/MVController.php b/app/Controllers/MVController.php index f9dec40..5705606 100644 --- a/app/Controllers/MVController.php +++ b/app/Controllers/MVController.php @@ -63,7 +63,9 @@ abstract class MVController extends CommonController { //변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요 $this->validation = service('validation'); - $this->validation->setRules($this->getModel()->getFieldRules($action, $fields)); + foreach ($fields as $field) { + $this->validation->setRule($field, $this->getModel()->getFieldRule($action, $field)); + } if (!$this->validation->withRequest($this->request)->run()) { throw new \Exception("{$this->class_name} 작업 데이터 검증 오류발생\n" . implode( "\n", @@ -90,6 +92,8 @@ abstract class MVController extends CommonController } protected function create_process(): void { + $this->create_validate($this->action, $this->fields); + $this->formDatas = $this->getFormDatas(); $this->entity = $this->getModel()->create(formDatas: $this->formDatas); } final protected function create_procedure(): RedirectResponse @@ -149,6 +153,8 @@ abstract class MVController extends CommonController } protected function modify_process(string $uid): void { + $this->modify_validate($this->action, $this->fields); + $this->formDatas = $this->getFormDatas(); $this->entity = $this->getModel()->getEntityByPK(intval($uid)); if ($this->entity === null) { throw new \Exception("{$uid} 정보를 찾을수 없습니다."); @@ -179,8 +185,6 @@ abstract class MVController extends CommonController { $this->action = __FUNCTION__; $this->field = [$field]; - $this->modify_validate($this->action, $this->fields); - $this->formDatas = $this->getFormDatas(); return $this->modify_procedure($uid); } //일괄처리작업 diff --git a/app/Helpers/Admin/User_helper.php b/app/Helpers/Admin/User_helper.php index c37d64c..24038be 100644 --- a/app/Helpers/Admin/User_helper.php +++ b/app/Helpers/Admin/User_helper.php @@ -76,14 +76,6 @@ function getFieldView_UserHelper(string $field, UserEntity $entity, array $viewD ); break; case 'role': - foreach ($viewDatas['field_options'][$field] as $key => $label) { - $roles = explode(DEFAULTS["DELIMITER_ROLE"], $value); - $checkboxs[] = form_checkbox("roles[]", $key, in_array($key, $roles)) . $label; - } - $checkbox_form = implode(" ", $checkboxs); - $checkbox_form .= form_submit("", '권한처리', ["formaction" => current_url() . "/roles/{$entity->getPK()}", "class" => "btn btn-outline-primary"]); - $checkbox_form .= form_close(); - $value = $checkbox_form; break; case 'updated_at': case 'created_at': diff --git a/app/Models/Cloudflare/AccountModel.php b/app/Models/Cloudflare/AccountModel.php index c91867c..4a426de 100644 --- a/app/Models/Cloudflare/AccountModel.php +++ b/app/Models/Cloudflare/AccountModel.php @@ -26,23 +26,23 @@ class AccountModel extends CommonModel { return self::TITLE; } - public function getFieldRule(string $action, string $field, array $rules): array + public function getFieldRule(string $action, string $field): string { switch ($field) { case self::PARENT: - $rules[$field] = "required|numeric"; + $rule = "required|numeric"; break; case self::TITLE: - $rules[$field] = "required|trim|string"; + $rule = "required|trim|string"; break; case "type": - $rules[$field] = "if_exist|in_list[standard,enterprise]"; + $rule = "if_exist|in_list[standard,enterprise]"; break; default: - $rules = parent::getFieldRule($action, $field, $rules); + $rule = parent::getFieldRule($action, $field); break; } - return $rules; + return $rule; } public function getFormFieldOption(string $field, array $options = []): array { diff --git a/app/Models/Cloudflare/AuthModel.php b/app/Models/Cloudflare/AuthModel.php index 71574f2..d3b7e2f 100644 --- a/app/Models/Cloudflare/AuthModel.php +++ b/app/Models/Cloudflare/AuthModel.php @@ -24,25 +24,25 @@ class AuthModel extends CommonModel { return self::TITLE; } - public function getFieldRule(string $action, string $field, array $rules): array + public function getFieldRule(string $action, string $field): string { switch ($field) { case self::TITLE: - $rules[$field] = "required|trim|valid_email"; - $rules[$field] .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : ""; + $rule = "required|trim|valid_email"; + $rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : ""; break; case "authkey": - $rules[$field] = "required|trim|string"; - $rules[$field] .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : ""; + $rule = "required|trim|string"; + $rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : ""; break; case "oldkey": - $rules[$field] = "if_exist|trim|string"; + $rule = "if_exist|trim|string"; break; default: - $rules = parent::getFieldRule($action, $field, $rules); + $rule = parent::getFieldRule($action, $field); break; } - return $rules; + return $rule; } public function getFormFieldOption(string $field, array $options = []): array { diff --git a/app/Models/Cloudflare/RecordModel.php b/app/Models/Cloudflare/RecordModel.php index 21981bb..76bd73c 100644 --- a/app/Models/Cloudflare/RecordModel.php +++ b/app/Models/Cloudflare/RecordModel.php @@ -27,33 +27,33 @@ class RecordModel extends CommonModel { return self::TITLE; } - public function getFieldRule(string $action, string $field, array $rules): array + public function getFieldRule(string $action, string $field): string { switch ($field) { case self::PARENT: - $rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]"; + $rule = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]"; break; case self::TITLE: case "content": - $rules[$field] = "required|trim|string"; + $rule = "required|trim|string"; break; case "type": - $rules[$field] = "required|in_list[A,AAAA,CNAME,NS,MX,PTR,SPF,TXT,SRV,INFO]"; + $rule = "required|in_list[A,AAAA,CNAME,NS,MX,PTR,SPF,TXT,SRV,INFO]"; break; case "ttl": - $rules[$field] = "if_exist|numeric"; + $rule = "if_exist|numeric"; break; case "proxiable": case "proxied": case "fixed": case "locked": - $rules[$field] = "if_exist|in_list[on,off]"; + $rule = "if_exist|in_list[on,off]"; break; default: - $rules = parent::getFieldRule($action, $field, $rules); + $rule = parent::getFieldRule($action, $field); break; } - return $rules; + return $rule; } public function getFormFieldInputOption(string $field, array $options = []): array { diff --git a/app/Models/Cloudflare/ZoneModel.php b/app/Models/Cloudflare/ZoneModel.php index 7f6ecb6..5d17e6c 100644 --- a/app/Models/Cloudflare/ZoneModel.php +++ b/app/Models/Cloudflare/ZoneModel.php @@ -26,29 +26,29 @@ class ZoneModel extends CommonModel { return self::TITLE; } - public function getFieldRule(string $action, string $field, array $rules): array + public function getFieldRule(string $action, string $field): string { switch ($field) { case self::PARENT: - $rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]"; + $rule = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]"; break; case self::TITLE: case "plan": - $rules[$field] = "required|trim|string"; + $rule = "required|trim|string"; break; case "name_servers": case "security_level": - $rules[$field] = "if_exist|trim|string"; + $rule = "if_exist|trim|string"; break; case "development_mode": case "ipv6": - $rules[$field] = "if_exist|in_list[on,off]"; + $rule = "if_exist|in_list[on,off]"; break; default: - $rules = parent::getFieldRule($action, $field, $rules); + $rule = parent::getFieldRule($action, $field); break; } - return $rules; + return $rule; } public function getFormFieldOption(string $field, array $options = []): array { diff --git a/app/Models/CommonModel.php b/app/Models/CommonModel.php index 8255760..42d0f21 100644 --- a/app/Models/CommonModel.php +++ b/app/Models/CommonModel.php @@ -62,7 +62,7 @@ abstract class CommonModel extends Model // { // return array_diff($this->allowedFields, $except_fields); //제외한 fields // } - public function getFieldRule(string $action, string $field, array $rules): array + public function getFieldRule(string $action, string $field): string { if (is_array($field)) { throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true)); @@ -71,48 +71,45 @@ abstract class CommonModel extends Model case $this->getPKField(): //수동입력인경우 if (!$this->useAutoIncrement) { - $rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]"; - $rules[$field] .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : ""; + $rule = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]"; + $rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : ""; } else { - $rules[$field] = "required|numeric"; + $rule = "required|numeric"; }; break; case $this->getTitleField(): - $rules[$field] = "required|string"; + $rule = "required|string"; break; case "passwd": - $rules[$field] = $action == "create" ? "required" : "if_exist" . "|trim|string"; + $rule = $action == "create" ? "required" : "if_exist" . "|trim|string"; break; case "confirmpassword": $rules["confirmpassword"] = $action == "create" ? "required" : "if_exist" . "|trim|string|matches[passwd]"; break; case "email": - $rules[$field] = "if_exist|trim|valid_email"; + $rule = "if_exist|trim|valid_email"; break; case 'image': - $rules[$field] = "is_image[{$field}]|mime_in[{$field},image/jpg,image/jpeg,image/gif,image/png,image/webp]|max_size[{$field},300]|max_dims[{$field},2048,768]"; + $rule = "is_image[{$field}]|mime_in[{$field},image/jpg,image/jpeg,image/gif,image/png,image/webp]|max_size[{$field},300]|max_dims[{$field},2048,768]"; break; case "status": - $rules[$field] = "if_exist|in_list[use,unuse]"; + $rule = "if_exist|in_list[use,unuse]"; break; case "updated_at": case "created_at": case "deleted_at": - $rules[$field] = "if_exist|valid_date"; + $rule = "if_exist|valid_date"; break; default: - $rules[$field] = "if_exist|string"; + $rule = "if_exist|string"; break; } - return $rules; + return $rule; } - final public function getFieldRules(string $action, array $fields, array $rules = []): array + final public function getFieldRules(string $action, array $fields, $rules = []): array { foreach ($fields as $field) { - if (is_array($field)) { - throw new \Exception(__FUNCTION__ . "에서 field array 입니다.\n" . var_export($field, true)); - } - $rules = $this->getFieldRule($action, $field, $rules); + $rules[$field] = $this->getFieldRule($action, $field); } return $rules; } diff --git a/app/Models/MapurlModel.php b/app/Models/MapurlModel.php index 328b291..3c598e1 100644 --- a/app/Models/MapurlModel.php +++ b/app/Models/MapurlModel.php @@ -26,24 +26,24 @@ class MapurlModel extends CommonModel { return self::TITLE; } - public function getFieldRule(string $action, string $field, array $rules): array + public function getFieldRule(string $action, string $field): string { if (is_array($field)) { throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true)); } switch ($field) { case "oldurl": - $rules[$field] = "required|valid_url_strict"; - $rules[$field] .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : ""; + $rule = "required|valid_url_strict"; + $rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : ""; break; case "newurl": - $rules[$field] = "required|valid_url_strict"; + $rule = "required|valid_url_strict"; break; default: - $rules = parent::getFieldRule($action, $field, $rules); + $rule = parent::getFieldRule($action, $field); break; } - return $rules; + return $rule; } public function getEntityByPK(int $uid): null|MapurlEntity { diff --git a/app/Models/SNSUserModel.php b/app/Models/SNSUserModel.php index 3c5ec20..c3ecfdc 100644 --- a/app/Models/SNSUserModel.php +++ b/app/Models/SNSUserModel.php @@ -28,23 +28,23 @@ class SNSUserModel extends CommonModel { return self::TITLE; } - public function getFieldRule(string $action, string $field, array $rules): array + public function getFieldRule(string $action, string $field): string { switch ($field) { case "id": - $rules[$field] = "required|trim|min_length[4]|max_length[20]|is_unique[{$this->table}.{$field}]"; + $rule = "required|trim|min_length[4]|max_length[20]|is_unique[{$this->table}.{$field}]"; break; case $this->getTitleField(): - $rules[$field] = "required|trim|string"; + $rule = "required|trim|string"; break; case "email": - $rules[$field] = "if_exist|trim|valid_email"; + $rule = "if_exist|trim|valid_email"; break; default: - $rules = parent::getFieldRule($action, $field, $rules); + $rule = parent::getFieldRule($action, $field); break; } - return $rules; + return $rule; } public function getEntityByPK(int $uid): null|SNSUSerEntity { diff --git a/app/Models/UserModel.php b/app/Models/UserModel.php index 395d396..81ade6b 100644 --- a/app/Models/UserModel.php +++ b/app/Models/UserModel.php @@ -30,35 +30,28 @@ class UserModel extends CommonModel { return self::TITLE; } - public function getFieldRule(string $action, string $field, array $rules): array + public function getFieldRule(string $action, string $field): string { if (is_array($field)) { throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true)); } switch ($field) { case "id": - $rules[$field] = "required|trim|min_length[4]|max_length[20]|is_unique[{$this->table}.{$field}]"; - $rules[$field] .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : ""; + $rule = "required|trim|min_length[4]|max_length[20]|is_unique[{$this->table}.{$field}]"; + $rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : ""; break; case "email": - $rules[$field] = "if_exist|trim|valid_email"; + $rule = "if_exist|trim|valid_email"; break; case "role": - //아래 Rule은 입력시에는 되는데 수정시에는 않됨 이유를 ? - // $rules[$field] = "required|in_list[master,director,cloudflare,manager,gold,silver,brone,vip,user]"; - //아래 Rule은 checkbox를 사용시에는 required만 우선 써야 수정시 validate문제없음 - $rules[$field] = "required|trim|string"; - break; - case "role[]": - case "roles[]": - $rules[$field] = "if_exist|trim|string"; + $rule = "required|trim|string"; break; case "passwd": default: - $rules = parent::getFieldRule($action, $field, $rules); + $rule = parent::getFieldRule($action, $field); break; } - return $rules; + return $rule; } public function getEntityByPK(int $uid): null|UserEntity