119 lines
4.4 KiB
PHP
119 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin\Cloudflare;
|
|
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
use App\Libraries\MyCloudflare\Zone;
|
|
use App\Libraries\MyCloudflare\Record;
|
|
|
|
class ZoneController extends CloudflareController
|
|
{
|
|
private $_myLibrary = null;
|
|
private $_account_entity = null;
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
$this->class_name = "Zone";
|
|
$this->class_path .= $this->class_name;
|
|
$this->title = lang("{$this->class_path}.title");
|
|
helper($this->class_name);
|
|
}
|
|
final protected function getMyLibrary(): Zone
|
|
{
|
|
if ($this->_myLibrary === null) {
|
|
$this->_myLibrary = new Zone($this->_account_entity);
|
|
}
|
|
return $this->_myLibrary;
|
|
}
|
|
protected function getFormFieldOption(string $field, array $options = []): array
|
|
{
|
|
switch ($field) {
|
|
case $this->getMyLibrary()->getMyStorage()::PARENT:
|
|
$this->getAccountModel()->where('status', DEFAULTS['STATUS']);
|
|
$options[$field] = [
|
|
DEFAULTS['EMPTY'] => lang($this->_className . '.label.' . $field) . ' 선택',
|
|
...$this->getAccountModel()->getFormFieldOption($field, $options),
|
|
];
|
|
break;
|
|
default:
|
|
$options = parent::getFormFieldOption($field, $options);
|
|
break;
|
|
}
|
|
return $options;
|
|
}
|
|
protected function getFormData(string $field): void
|
|
{
|
|
switch ($field) {
|
|
case 'domains':
|
|
$this->formDatas[$field] = explode("\n", $this->request->getVar($field));
|
|
if (!is_array($this->formDatas[$field]) || !count($this->formDatas[$field])) {
|
|
throw new \Exception("도메인명이 정의되지 않았습니다.");
|
|
}
|
|
break;
|
|
case 'hosts':
|
|
$this->formDatas[$field] = $this->request->getVar($field);
|
|
if (!is_array($this->formDatas[$field]) || !count($this->formDatas[$field])) {
|
|
throw new \Exception("호스트명이 정의되지 않았습니다");
|
|
}
|
|
break;
|
|
default:
|
|
$this->formDatas[$field] = $this->request->getVar($field);
|
|
break;
|
|
}
|
|
}
|
|
//전송된 데이터 검증
|
|
protected function validateFormData(string $field): void
|
|
{
|
|
switch ($field) {
|
|
case 'domains':
|
|
case 'hosts':
|
|
break;
|
|
default:
|
|
parent::validateFormData($field);
|
|
break;
|
|
}
|
|
}
|
|
protected function create_init(): void
|
|
{
|
|
$this->action = 'create';
|
|
$this->fields = [$this->getMyLibrary()->getMyStorage()::PARENT, 'domains', 'hosts', 'type', 'content', 'proxied'];
|
|
$this->filter_fields = [$this->getMyLibrary()->getMyStorage()::PARENT, 'type', 'proxied'];
|
|
$this->field_rules = $this->getFormFieldRules();
|
|
$this->field_options = $this->getFormFieldOptions();
|
|
$this->getMyLibrary()->getMyStorage()->setAction($this->action);
|
|
}
|
|
// public function create_form(): RedirectResponse|string
|
|
// {
|
|
// return $this->create_form_process();
|
|
// }
|
|
protected function create_process_submit(): void
|
|
{
|
|
foreach ($this->formDatas['domains'] as $domain) {
|
|
//Zone생성
|
|
$zone_entity = $this->getMyLibrary()->create($domain);
|
|
//Record생성
|
|
$record = new Record($this->_account_entity, $zone_entity);
|
|
foreach ($this->formDatas['hosts'] as $host) {
|
|
$record->create($host, [
|
|
'type' => $this->formDatas['type'],
|
|
'content' => $this->formDatas['content'],
|
|
'proxied' => $this->formDatas['proxied'],
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
public function create(string $account_uid): RedirectResponse
|
|
{
|
|
$this->_account_entity = $this->getAccountModel()->getEntityByPK($account_uid);
|
|
$this->formDatas = [];
|
|
$this->getFormDatas();
|
|
$this->convertFormDatas();
|
|
$this->validateFormDatas();
|
|
return parent::create_process();
|
|
}
|
|
}
|