71 lines
2.5 KiB
PHP
71 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Libraries\MyCloudflare;
|
|
|
|
use Cloudflare\API\Adapter\Guzzle;
|
|
use App\Models\Cloudflare\AccountModel;
|
|
use App\Libraries\MyCloudflare\MyCloudflare;
|
|
use App\Entities\Cloudflare\AccountEntity;
|
|
|
|
class Account extends MyCloudflare
|
|
{
|
|
private $_myStorage = null;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
final protected function getMyStorage(): AccountModel
|
|
{
|
|
if ($this->_myStorage === null) {
|
|
$this->_myStorage = new AccountModel();
|
|
}
|
|
return $this->_myStorage;
|
|
}
|
|
//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"}
|
|
// ]
|
|
protected function getArrayByResult($result): array
|
|
{
|
|
$formDatas[$this->getMyStorage()->getPKField()] = $result->id;
|
|
$formDatas[$this->getMyStorage()->getTitleField()] = $result->name;
|
|
$formDatas['type'] = $result->type;
|
|
$formDatas['status'] = 'use';
|
|
$formDatas['updated_at'] = $result->created_on;
|
|
$formDatas['created_at'] = $result->created_on;
|
|
return $formDatas;
|
|
}
|
|
public function create(array $formDatas): AccountEntity
|
|
{
|
|
//Socket용
|
|
$cf = $this->getMySocket()->request($formDatas['apikey'])
|
|
->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);
|
|
$entity = $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));
|
|
}
|
|
}
|