class_name = "Zone"; $this->class_path .= $this->class_name; $this->title = lang("{$this->class_path}.title"); helper($this->class_path); } final protected function getModel(): ZoneModel { if ($this->_model === null) { $this->_model = new ZoneModel(); } return $this->_model; } final protected function getMySocket(): ZoneSocket { if ($this->_mySocket === null) { $this->_mySocket = new ZoneSocket($this->_account_entity); } return $this->_mySocket; } protected function getFormFieldOption(string $field, array $options = []): array { switch ($field) { case $this->getModel()::PARENT: $this->getAccountModel()->where('status', DEFAULTS['STATUS']); $options[$field] = [ DEFAULTS['EMPTY'] => lang($this->class_path . '.label.' . $field) . ' 선택', ...$this->getAccountModel()->getFormFieldOption($field, $options), ]; // echo $this->getAccountModel()->getLastQuery(); // dd($options); break; default: $options = parent::getFormFieldOption($field, $options); break; } return $options; } protected function getFormData(string $field, array $formDatas): array { switch ($field) { case 'domains': $formDatas[$field] = explode("\n", $this->request->getVar($field)); if (!is_array($formDatas[$field]) || !count($formDatas[$field])) { throw new \Exception("도메인명이 정의되지 않았습니다."); } break; case 'hosts': $formDatas[$field] = $this->request->getVar($field); if (!is_array($formDatas[$field]) || !count($formDatas[$field])) { throw new \Exception("호스트명이 정의되지 않았습니다"); } break; default: $formDatas = parent::getFormData($field, $formDatas); break; } return $formDatas; } private function init(string $action): void { $this->fields = [$this->getModel()::PARENT, 'domains', 'hosts', 'type', 'content', 'proxied']; $this->field_rules = $this->getModel()->getFieldRules($action, $this->fields); $this->filter_fields = [$this->getModel()::PARENT, 'development_mode', 'ipv6', 'security_level', 'status']; $this->field_options = $this->getFormFieldOptions($this->filter_fields); } //생성 protected function create_validate(array $fields): void { //domains,hosts를 제외한 fields Valid처리 parent::create_validate(array_diff($fields, ['domains', 'hosts'])); } protected function create_process(): void { parent::create_process(); //Zone생성 $zone_entitys = []; foreach ($this->formDatas['domains'] as $domain) { $entity = $this->getMySocket()->create($domain); log_message("debug", "Zone:{$entity->getTitle()} 작업을 완료하였습니다."); $zone_entitys[] = $entity; } //Record생성 foreach ($zone_entitys as $zone_entity) { $record_socket = new RecordSocket($entity); foreach ($this->formDatas['hosts'] as $host) { $entity = $record_socket->create($host, $this->formDatas['type'], $this->formDatas['content'], $this->formDatas['proxied']); log_message("debug", "Record:{$entity->getTitle()} 작업을 완료하였습니다."); } } } public function create(): RedirectResponse { $this->init(__FUNCTION__); $this->create_validate($this->_fields); $this->formDatas = $this->getFormDatas(); //부모데이터 정의 $this->_account_entity = $this->getAccountModel()->getEntityByPK($this->formDatas[$this->getModel()::PARENT]); return $this->create_procedure(); } // 리스트 public function index(): string { $this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'name_servers', 'original_name_servers', 'plan', 'development_mode', 'ipv6', 'security_level', 'status', 'updated_at', 'created_at']; $this->field_rules = $this->getModel()->getFieldRules(__FUNCTION__, $this->fields); $this->filter_fields = [$this->getModel()::PARENT, 'development_mode', 'ipv6', 'security_level', 'status']; $this->batchjob_fields = ['development_mode', 'ipv6', 'security_level']; $this->field_options = $this->getFormFieldOptions($this->filter_fields); return $this->list_procedure(); } //reload public function reload(): RedirectResponse { try { //Transaction Start $this->getModel()->transStart(); foreach ($this->getModel()->getEntitys as $entity) { $record_socket = new RecordSocket($entity); $record_socket->reload(); } 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']) ?: "/"); } } }