session = $this->session_AccountTrait(); $this->class_name = 'Account'; helper($this->class_name); } final protected function getMySocket(): AccountSocket { if ($this->_mySocket === null) { $this->_mySocket = new AccountSocket($auth_uid); } return $this->_mySocket; } final protected function getModel(): AccountModel { if ($this->_model === null) { $this->_model = new AccountModel(); } return $this->_model; } protected function create_form_process(): void { $this->fields = ['id', 'authkey']; $this->filter_fields = ['status']; parent::create_form_process(); } public function create_form(): RedirectResponse|string { try { $this->fields = ['id', 'authkey']; $this->filter_fields = ['status']; $this->action = 'create'; $this->getModel()->setAction($this->action); $this->session->keepFlashdata(SESSION_NAMES['RETURN_URL']); return view("/{$this->class_name}/insert", ['attributes' => $this->getAttributes]); } catch (\Exception $e) { log_message("error", $e->getMessage()); return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/")->with(SESSION_NAMES['RETURN_MSG'], $e->getMessage()); } } protected function create_process($model): AccountEntity { $datas = [ 'name' => $name . "'s Account", 'type' => 'standard', ]; $result = $this->getClient()->post("accounts", $datas); $result = json_decode($result->getBody()); if (!$result->success) { throw new \Exception(var_export($result, true)); } //Result 형태 // [ // {"id":"078e88a7735965b661715af13031ecb0", // "name":"Cloudwin002@idcjp.jp's Auth", // "type":"standard", // "settings":{ // "enforce_twofactor":false, // "api_access_enabled":null, // "access_approval_expiry":null, // "use_account_custom_ns_by_default":false // }, // "legacy_flags":{"enterprise_zone_quota":{"maximum":0,"current":0,"available":0}}, // "created_on":"2017-06-26T05:44:49.470184Z"} // ] $formDatas[$this->getAuthModel()->PK()] = $result->id; $formDatas[$this->getAuthModel()->getTitleField()] = $result->name; $formDatas['type'] = $result->type; $formDatas['status'] = 'use'; $formDatas['updated_at'] = $result->created_on; $formDatas['created_at'] = $result->created_on; return parent::create_process($model); } public function create(): RedirectResponse { $this->getModel()->transStart(); try { $this->fields = ['id', 'authkey']; $this->filter_fields = ['status']; $this->action = 'create'; $this->getModel()->setAction($this->action); $entity = $this->create_process($this->getModel()); log_message("notice", __FUNCTION__ . "=>{$entity->getTitle()} 작업을 완료하였습니다."); 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()); $this->session->keepFlashdata(SESSION_NAMES['RETURN_URL']); return redirect()->back()->withInput(); } } }