class_name .= "Record"; $this->layout = LAYOUTS['admin']; $this->title = lang("{$this->class_name}.title"); helper($this->class_name); } final protected function getMyLibrary(): Record { if ($this->_myLibrary === null) { $this->_myLibrary = new Record($this->_account_entity, $this->_zone_entity); } return $this->_myLibrary; } protected function getFormFieldInputOption(string $field, array $options = []): array { switch ($field) { case $this->getMyLibrary()->getMyStorage()::PARENT: $options = [ DEFAULTS['EMPTY'] => lang($this->_className . '.label.' . $field) . ' 선택' ]; $this->getZoneModel()->where('status', DEFAULTS['STATUS']); $options = $this->getZoneModel()->getFormFieldInputOption($field, $options); break; default: $options = parent::getFormFieldInputOption($field, $options); break; } return $options; } //전송된 데이터 protected function getFormData(string $field): void { switch ($field) { case 'hosts': $this->formDatas[$field] = explode("\n", $this->request->getVar($field)); if (!is_array($this->formDatas[$field]) || !count($this->formDatas[$field])) { throw new \Exception("호스트명이 정의되지 않았습니다."); } break; default: $this->formDatas[$field] = $this->request->getVar($field); break; } } //전송된 데이터 검증 protected function validateFormData(string $field): void { switch ($field) { case 'hosts': break; default: parent::validateFormData($field); break; } } protected function create_init(): void { $this->fields = [ $this->getMyLibrary()->getMyStorage()::PARENT, 'type', 'content', 'proxied', 'hosts', ]; $this->filter_fields = [$this->getMyLibrary()->getMyStorage()::PARENT, 'type', 'proxied']; $this->action = 'create'; $this->getMyLibrary()->getMyStorage()->setAction($this->action); } // public function create_form(): RedirectResponse|string // { // return $this->create_form_process(); // } protected function create_process_submit(): void { //Record생성 foreach ($this->formDatas['hosts'] as $host) { $this->getMyLibrary()->create($host, $this->formDatas); } } public function create(string $zone_uid): RedirectResponse { $this->_zone_entity = $this->getZoneModel()->getEntityByPK($zone_uid); $this->_account_entity = $this->getAccountModel()->getEntityByPK($this->_zone_entity->getParent()); $this->formDatas = []; $this->getFormDatas(); $this->convertFormDatas(); $this->validateFormDatas(); return parent::create_process(); } }