class_name = "Mapurl"; $this->class_path = $this->root . $this->class_name; $this->title = lang("{$this->class_path}.title"); helper($this->class_path); } protected function getModel(): MapurlModel { if ($this->_model === null) { $this->_model = new MapurlModel(); } return $this->_model; } protected function getFormFieldOption(string $field, array $options = []): array { switch ($field) { default: $options = parent::getFormFieldOption($field, $options); break; } return $options; } protected function getFormData(string $field, array $formDatas): array { switch ($field) { default: $formDatas = parent::getFormData($field, $formDatas); break; } return $formDatas; } private function init(string $action): void { $this->action = $action; $this->fields = [$this->getModel()::TITLE, 'newurl', 'status']; $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); $this->filter_fields = ['status']; $this->field_options = $this->getFormFieldOptions($this->filter_fields); } private function remaping_process(): void { //모든 필요한 FormOption등 조기화작업 필요 $this->getModel()->where('status', DEFAULTS['STATUS']); $this->getModel()->orderBy('oldurl', 'ASC'); //html의 case문 설정 $urls = array(""); foreach ($this->getModel()->getEntitys() as $entity) { $temp_oldurl = sprintf("case '%s':", trim($entity->oldurl)); //한글을 포함하고 있는지 체크 if (preg_match("/[\xE0-\xFF][\x80-\xFF][\x80-\xFF]/", $entity->oldurl)) { //도메인 URL 분리 preg_match("/^(https?:\/\/)(.*)/", $entity->oldurl, $matches); $temp_oldurl = sprintf("case '%s%s':\ncase '%s':", $matches[1], idn_to_ascii($matches[2]), trim($entity->oldurl)); } array_push($urls, sprintf("\t\t\t%s\n \t\t\twindow.location.href='%s';\n \t\tbreak;", $temp_oldurl, trim($entity->newurl))); } $remap_page = view($this->class_path . DIRECTORY_SEPARATOR . __FUNCTION__, ["urls" => $urls]); $remap_path = FCPATH . DIRECTORY_SEPARATOR . "mapurl"; //디렉토리 생성 여부 확인 if (!is_dir($remap_path)) { mkdir($remap_path, 0755, true); } //htmlBuild용 if (!file_put_contents($remap_path . '/index.html', $remap_page)) { throw new \Exception(__FUNCTION__ . "에서 " . $remap_path . "/index.html Write 실패"); } } //생성 public function create_form(): RedirectResponse|string { $this->init('create'); return $this->create_form_procedure(); } protected function create_process(): void { $this->create_validate($this->action, $this->fields); $this->formDatas = $this->getFormDatas(); parent::create_process(); $this->entity = $this->getModel()->create(formDatas: $this->formDatas); $this->remaping_process(); } public function create(): RedirectResponse { $this->init(__FUNCTION__); return $this->create_procedure(); } //수정 protected function modify_form_process(string $uid): void { $this->entity = $this->getModel()->getEntityByPK(intval($uid)); if ($this->entity === null) { throw new \Exception("해당 정보를 찾을수 없습니다."); } parent::modify_form_process($uid); } public function modify_form(string $uid): RedirectResponse|string { $this->init('modify'); return $this->modify_form_procedure($uid); } protected function modify_process(string $uid): void { $this->entity = $this->getModel()->getEntityByPK(intval($uid)); if ($this->entity === null) { throw new \Exception("{$uid} 정보를 찾을수 없습니다."); } $this->modify_validate($this->action, $this->fields); $this->formDatas = $this->getFormDatas(); parent::modify_process($uid); $this->entity = $this->getModel()->modify($this->entity, $this->formDatas); $this->remaping_process(); } public function modify(string $uid): RedirectResponse { $this->init(__FUNCTION__); return $this->modify_procedure($uid); } // 리스트 public function index(): string { $this->action = __FUNCTION__; $this->fields = [$this->getModel()::TITLE, 'newurl', 'status']; $this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields); $this->filter_fields = ['status']; $this->field_options = $this->getFormFieldOptions($this->filter_fields); $this->batchjob_fields = ['status']; return $this->list_procedure(); } }