cfmgrv4 init...1

This commit is contained in:
최준흠 2024-09-27 08:30:27 +09:00
parent 958da4e1ee
commit 5c7aeb0625
5 changed files with 18 additions and 40 deletions

View File

@ -10,15 +10,11 @@ use App\Entities\Cloudflare\AccountEntity;
class Account extends MyCloudflare
{
private $_myStorage = null;
private $_authkey = "";
public function __construct()
public function __construct(string $auth_key)
{
parent::__construct();
}
private function getRequest(): Guzzle
{
return $this->getMySocket()->request($this->_authkey);
parent::__construct($auth_key);
}
final protected function getMyStorage(): AccountModel
{
if ($this->_myStorage === null) {
@ -72,7 +68,7 @@ class Account extends MyCloudflare
{
//Account의 경우 인증키를 가지고있고 생성할수 없으므로 get으로 읽은후 첫번째것을 사용하기로 함
$entitys = [];
foreach ($this->reload_cfs($this->getRequest(), 'accounts') as $cf) {
foreach ($this->reload_cfs($this->getMySocket(), 'accounts') as $cf) {
$formDatas = $this->getArrayByResult($cf->result);
$entity = $this->$this->getMyStorage()->create($formDatas);
log_message("notice", "Account:" . __FUNCTION__ . "=> {$entity->getTitle()} 작업을 완료하였습니다.");

View File

@ -8,10 +8,12 @@ use App\Libraries\CommonLibrary;
abstract class MyCloudflare extends CommonLibrary
{
private $_account_uid = "";
private $_mySocket = null;
protected function __construct()
protected function __construct(string $account_uid)
{
parent::__construct();
$this->_account_uid = $account_uid;
}
abstract protected function getArrayByResult($result, array $formDatas = []): array;
abstract protected function reload_entity($cf): mixed;

View File

@ -16,14 +16,10 @@ class Record extends MyCloudflare
private $_zone_entity = null;
public function __construct(AccountEntity $account_entity, ZoneEntity $zone_entity)
{
parent::__construct();
parent::__construct($this->_account_entity->getPK());
$this->_account_entity = $account_entity;
$this->_zone_entity = $zone_entity;
}
protected function getRequest(): Guzzle
{
return $this->getMySocket()->request($this->_account_entity->getAuthKey());
}
final protected function getMyStorage(): RecordModel
{
if ($this->_myStorage === null) {

View File

@ -15,13 +15,9 @@ class Zone extends MyCloudflare
private $_account_entity = null;
public function __construct(AccountEntity $account_entity)
{
parent::__construct();
parent::__construct($this->_account_entity->getPK());
$this->_account_entity = $account_entity;
}
private function getRequest(): Guzzle
{
return $this->getMySocket()->request($this->_account_entity->getAuthKey());
}
final protected function getMyStorage(): ZoneModel
{
if ($this->_myStorage === null) {
@ -29,6 +25,10 @@ class Zone extends MyCloudflare
}
return $this->_myStorage;
}
final protected function getRequest(): Guzzle
{
return $this->getMySocket()->request($this->_account_uid);
}
protected function getArrayByResult($result, array $formDatas = []): array
{
$formDatas[$this->getMyStorage()->getPKField()] = $result->id;

View File

@ -7,10 +7,6 @@ use Cloudflare\API\Auth\APIKey;
use Cloudflare\API\Adapter\Guzzle;
use App\Models\Cloudflare\AccountModel;
use App\Libraries\CommonLibrary;
// use App\Entities\Cloudflare\AccountEntity;
// use Cloudflare\API\Endpoints\Zones;
// use Cloudflare\API\Endpoints\DNS;
// use Cloudflare\API\Endpoints\Accounts;
class CloudflareSocket extends CommonLibrary
{
@ -35,15 +31,15 @@ class CloudflareSocket extends CommonLibrary
private function initAdapters(): void
{
foreach ($this->getAccountModel()->getEntitys() as $entity) {
$this->_clients[$entity->getAuthKey()] = new Guzzle(
$this->_clients[$entity->getPK()] = new Guzzle(
new APIKey($entity->getTitle(), $entity->getAuthKey())
);
}
}
final public function request(string $authkey): Guzzle
final public function request(string $key): Guzzle
{
if (!array_key_exists($authkey, $this->_clients)) {
throw new \Exception(+__FUNCTION__ . " => {$authkey}에 해당하는 Adapter를 찾을수 없습니다.");
if (!array_key_exists($key, $this->_clients)) {
throw new \Exception(+__FUNCTION__ . " => {$key}에 해당하는 Adapter를 찾을수 없습니다.");
}
if (self::$_request >= self::$_request_max) {
log_message('warning', sprintf("--Cloudflare API Call %s초 대기 시작--", self::$_request_timewait));
@ -52,18 +48,6 @@ class CloudflareSocket extends CommonLibrary
log_message('warning', sprintf("--Cloudflare API Call %s초 대기 종료--", self::$_request_timewait));
}
self::$_request++;
return $this->_clients[$authkey];
return $this->_clients[$key];
}
// public function getAccount(string $authkey): Accounts
// {
// return new Accounts($this->request($authkey));
// }
// public function getZone(string $authkey): Zones
// {
// return new Zones($this->request($authkey));
// }
// public function getRecord(string $authkey): DNS
// {
// return new DNS($this->request($authkey));
// }
}