_className = 'Cloudflare'; $this->_viewPath = $this->_viewPath . '/cloudflare'; } final protected function getAuthModel(): AuthModel { return is_null($this->_authModel) ? new AuthModel() : $this->_authModel; } final protected function getAccountModel(): AccountModel { return is_null($this->_accountModel) ? new AccountModel() : $this->_accountModel; } final protected function getZoneModel(): ZoneModel { return is_null($this->_zoneModel) ? new ZoneModel() : $this->_zoneModel; } final protected function getRecordModel(): RecordModel { return is_null($this->_recordModel) ? new RecordModel() : $this->_recordModel; } //Zone입력 final protected function insert_Zone(string $account_uid, string $domain): \App\Entities\Cloudflare\ZoneEntity { $fieldDatas = array('account_uid' => $account_uid, 'domain' => $domain); $api = new \App\Libraries\Cloudflare\API\Zone(); $zone = $api->insert($fieldDatas); if (!$this->getZoneModel()->save($zone)) { Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getZoneModel()->getLastQuery()); Log::add("error", implode("\n", $this->getZoneModel()->errors())); throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->getZoneModel()->errors(), true)); } Log::add("info", "Zone: {$zone->getTitle()} 등록"); return $zone; } //Record입력 final protected function insert_Host( string $zone_uid, string $host, string $type, string $content, string $proxied ): \App\Entities\Cloudflare\RecordEntity { $fieldDatas = array('zone_uid' => $zone_uid, 'host' => $host); $fieldDatas['type'] = $type; $fieldDatas['content'] = $content; $fieldDatas['proxied'] = $proxied; $api = new \App\Libraries\Cloudflare\API\Record(); $record = $api->insert($fieldDatas); $record->fixed = 'off'; //초기값 if (!$this->getRecordModel()->save($record)) { Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getRecordModel()->getLastQuery()); Log::add("error", implode("\n", $this->getRecordModel()->errors())); throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->getRecordModel()->errors(), true)); } Log::add("info", "Host: {$record->getTitle()} 등록"); return $record; } //Sync관련 protected function sync_process($entity) { return $entity; } final public function sync($uid) { try { $entity = $this->_model->getEntity($uid); $entity = $this->sync_process($entity); return alert_CommonHelper("{$this->_viewDatas['title']} " . __FUNCTION__ . " 완료하였습니다.", session()->get(RETURN_URL)); } catch (\Exception $e) { return alert_CommonHelper($e->getMessage(), 'back'); } } }