diff --git a/app/Libraries/MyCloudflare/Account.php b/app/Libraries/MyCloudflare/Account.php index beab6e4..da3e9c5 100644 --- a/app/Libraries/MyCloudflare/Account.php +++ b/app/Libraries/MyCloudflare/Account.php @@ -10,10 +10,15 @@ use App\Entities\Cloudflare\AccountEntity; class Account extends MyCloudflare { private $_myStorage = null; + private $_authkey = ""; public function __construct() { parent::__construct(); } + private function getRequest(): Guzzle + { + return $this->getMySocket()->request($this->_authkey); + } final public function getMyStorage(): AccountModel { if ($this->_myStorage === null) { @@ -45,24 +50,39 @@ class Account extends MyCloudflare $formDatas['created_at'] = $result->created_on; return $formDatas; } - public function create(array $formDatas): AccountEntity + // public function create(array $formDatas): AccountEntity + // { + // //Socket용 + // $cf = $this->getMySocket()->request($formDatas['authkey']) + // ->post('accounts', [ + // 'name' => $formDatas[$this->getMyStorage()->getTitleField()], + // 'type' => $formDatas['type'], + // ]); + // $cf = json_decode($cf->getBody()); + // if (!$cf->success) { + // throw new \Exception(__FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); + // } + // //Storage용 + // $formDatas = $this->getArrayByResult($cf->result, $formDatas); + // $entity = $this->getMyStorage()->create($formDatas); + // log_message("notice", "Account::" . __FUNCTION__ . "=> 작업을 완료하였습니다."); + // return $entity; + // } + public function create($formDatas): AccountEntity { - //Socket용 - $cf = $this->getMySocket()->request($formDatas['authkey']) - ->post('accounts', [ - 'name' => $formDatas[$this->getMyStorage()->getTitleField()], - 'type' => $formDatas['type'], - ]); - $cf = json_decode($cf->getBody()); + $this->_authkey = $formDatas['authkey']; + $cf = $this->getRequest()->get('accounts', ['page' => 1, 'per_page' => 20]); + $cf = json_decode($cf->getBody()); if (!$cf->success) { - throw new \Exception(__FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); + throw new \Exception("Account:" . __FUNCTION__ . "에서 실패:\n" . var_export($cf, true)); } - //Storage용 - $formDatas = $this->getArrayByResult($cf->result, $formDatas); - $entity = $this->getMyStorage()->create($formDatas); - log_message("notice", "Account::" . __FUNCTION__ . "=> 작업을 완료하였습니다."); + //Account의 경우 인증키를 가지고있고 생성할수 없으므로 get으로 읽은후 첫번째것을 사용하기로 함 + $formDatas = $this->getArrayByResult(array_shift($cf->result)); + $entity = $this->$this->getMyStorage()->create($formDatas); + log_message("notice", "Account:" . __FUNCTION__ . "=> 작업을 완료하였습니다."); return $entity; } + protected function reload_entity($cf): AccountEntity { return $this->getMyStorage()->modify(new AccountEntity, $this->getArrayByResult($cf));