68 lines
2.4 KiB
PHP
68 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
use App\Controllers\CommonController;
|
|
use App\Libraries\MySocket\Cloudflare\AccountSocket;
|
|
use App\Models\Cloudflare\AccountModel;
|
|
|
|
use App\Traits\AuthTrait;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class AccountController extends CommonController
|
|
{
|
|
use AuthTrait;
|
|
private $_mySocket = null;
|
|
private $_model = null;
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
$this->session = $this->loginCheck_AuthTrait();
|
|
}
|
|
final public function getMySocket(string $email, $api_key): AccountSocket
|
|
{
|
|
if ($this->_mySocket === null) {
|
|
$this->_mySocket = new AccountSocket($email, $api_key);
|
|
}
|
|
return $this->_mySocket;
|
|
}
|
|
final public function getModel(): AccountModel
|
|
{
|
|
if ($this->_model === null) {
|
|
$this->_model = new AccountModel();
|
|
}
|
|
return $this->_model;
|
|
}
|
|
public function create(string $email, $api_key, array $formDatas = [])
|
|
{
|
|
//전송
|
|
$result = $this->getMySocket($email, $api_key)->create($email);
|
|
//답변형태
|
|
// [
|
|
// {"id":"078e88a7735965b661715af13031ecb0",
|
|
// "name":"Cloudwin002@idcjp.jp's Account",
|
|
// "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->getModel()->getTitleField()] = $email;
|
|
$formDatas['key'] = $api_key;
|
|
$formDatas[$this->getModel()->PK()] = $result->id;
|
|
$formDatas[$this->getModel()->getTitleField()] = $result->name;
|
|
$formDatas['type'] = $result->type;
|
|
$formDatas['status'] = 'use';
|
|
$formDatas['updated_at'] = $result->created_on;
|
|
$formDatas['created_at'] = $result->created_on;
|
|
$entity = $this->getModel()->create($formDatas);
|
|
log_message("notice", __FUNCTION__ . "=> {$entity->getTitle()} 생성을 완료하였습니다.");
|
|
}
|
|
}
|