cfmgrv4 init...4

This commit is contained in:
최준흠 2024-10-24 17:45:12 +09:00
parent 36322a95de
commit cb5810855e
40 changed files with 648 additions and 371 deletions

View File

@ -2,40 +2,37 @@
namespace App\Controllers\Admin\Cloudflare; namespace App\Controllers\Admin\Cloudflare;
use App\Helpers\Cloudflare\AccountHelper;
use App\Models\Cloudflare\AccountModel;
use App\Services\Cloudflare\AccountService;
use CodeIgniter\HTTP\DownloadResponse; use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use App\Helpers\Cloudflare\AccountHelper;
use App\Models\Cloudflare\AccountModel;
use App\Services\Cloudflare\Account;
class AccountController extends CloudflareController class AccountController extends CloudflareController
{ {
private $_auth_entity = null; private $_auth_entity = null;
private $_myLibrays = [];
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->class_name = "Account"; $this->title = lang("{$this->getService()->class_path}.title");
$this->class_path .= $this->class_name;
$this->title = lang("{$this->class_path}.title");
$this->helper = new AccountHelper(); $this->helper = new AccountHelper();
} }
final protected function getModel(): AccountModel protected function getModel(): AccountModel
{ {
if ($this->model === null) { if ($this->_model === null) {
$this->model = new AccountModel(); $this->_model = new AccountModel();
} }
return $this->model; return $this->_model;
} }
final protected function getMyLibrary(): Account protected function getService(): AccountService
{ {
if (!isset($this->_myLibrays[$this->_auth_entity->getPK()])) { if ($this->service === null) {
$this->_myLibrays[$this->_auth_entity->getPK()] = new Account($this->_auth_entity); $this->service = new AccountService();
} }
return $this->_myLibrays[$this->_auth_entity->getPK()]; return $this->service;
} }
protected function getFormFieldOption(string $field, array $options = []): array protected function getFormFieldOption(string $field, array $options = []): array
{ {
@ -82,11 +79,12 @@ class AccountController extends CloudflareController
//reload Account By Auth //reload Account By Auth
protected function reload_process(mixed $uid): void protected function reload_process(mixed $uid): void
{ {
$this->_auth_entity = $this->getAuthModel()->getEntityByPK($uid); //부모데이터정의
if ($this->_auth_entity === null) { $this->auth_entity = $this->getAuthModel()->getEntityByPK($uid);
if ($this->auth_entity === null) {
throw new \Exception("Auth: {$uid} 정보를 찾을수 없습니다."); throw new \Exception("Auth: {$uid} 정보를 찾을수 없습니다.");
} }
$this->getMyLibrary()->reload(); $this->getService()->reload($this->auth_entity);
} }
public function reload(int $uid): RedirectResponse public function reload(int $uid): RedirectResponse
{ {

View File

@ -2,30 +2,36 @@
namespace App\Controllers\Admin\Cloudflare; namespace App\Controllers\Admin\Cloudflare;
use App\Helpers\Cloudflare\AuthHelper;
use App\Models\Cloudflare\AuthModel;
use App\Services\Cloudflare\AuthService;
use CodeIgniter\HTTP\DownloadResponse; use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use App\Helpers\Cloudflare\AuthHelper;
use App\Models\Cloudflare\AuthModel;
class AuthController extends CloudflareController class AuthController extends CloudflareController
{ {
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->class_name .= "Auth"; $this->title = lang("{$this->getService()->class_path}.title");
$this->class_path .= $this->class_name;
$this->title = lang("{$this->class_path}.title");
$this->helper = new AuthHelper(); $this->helper = new AuthHelper();
} }
final protected function getModel(): AuthModel protected function getModel(): AuthModel
{ {
if ($this->model === null) { if ($this->_model === null) {
$this->model = new AuthModel(); $this->_model = new AuthModel();
} }
return $this->model; return $this->_model;
}
protected function getService(): AuthService
{
if ($this->service === null) {
$this->service = new AuthService();
}
return $this->service;
} }
private function init(string $action, array $fields = []): void private function init(string $action, array $fields = []): void
{ {

View File

@ -21,8 +21,8 @@ abstract class CloudflareController extends AdminController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->class_path = "Cloudflare/"; $this->uri_path .= "cloudflare/";
$this->uri_path .= strtolower($this->class_path); // dd($this->uri_path);
} }
final protected function getAuthModel(): AuthModel final protected function getAuthModel(): AuthModel
{ {
@ -59,7 +59,7 @@ abstract class CloudflareController extends AdminController
$this->getModel()->transStart(); $this->getModel()->transStart();
try { try {
$this->sync_process($uid); $this->sync_process($uid);
$this->message = "{$this->class_name}: 동기화작업을 완료하였습니다."; $this->message = "{$this->getService()->class_name}: 동기화작업을 완료하였습니다.";
$this->getModel()->transCommit(); $this->getModel()->transCommit();
log_message("notice", __FUNCTION__ . $this->message); log_message("notice", __FUNCTION__ . $this->message);
// 이전 URL로 리다이렉트 // 이전 URL로 리다이렉트
@ -79,7 +79,7 @@ abstract class CloudflareController extends AdminController
$this->getModel()->transStart(); $this->getModel()->transStart();
try { try {
$this->reload_process($uid); $this->reload_process($uid);
$this->message = "{$this->class_name}: Reload 작업이 완료되었습니다."; $this->message = "{$this->getService()->class_name}: Reload 작업이 완료되었습니다.";
$this->getModel()->transCommit(); $this->getModel()->transCommit();
log_message("notice", __FUNCTION__ . $this->message); log_message("notice", __FUNCTION__ . $this->message);
// 이전 URL로 리다이렉트 // 이전 URL로 리다이렉트

View File

@ -2,26 +2,23 @@
namespace App\Controllers\Admin\Cloudflare; namespace App\Controllers\Admin\Cloudflare;
use App\Helpers\Cloudflare\FirewallHelper;
use CodeIgniter\HTTP\DownloadResponse; use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use App\Models\Cloudflare\FirewallModel; use App\Models\Cloudflare\FirewallModel;
use App\Services\Cloudflare\FirewallService;
use App\Helpers\Cloudflare\FirewallHelper;
use App\Models\Cloudflare\ZoneModel; use App\Models\Cloudflare\ZoneModel;
use App\Services\Cloudflare\Firewall;
class FirewallController extends CloudflareController class FirewallController extends CloudflareController
{ {
private $_zone_entity = null; private $_zone_entity = null;
private $_myLibrays = [];
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->class_name .= "Firewall"; $this->title = lang("{$this->getService()->class_path}.title");
$this->class_path .= $this->class_name;
$this->title = lang("{$this->class_path}.title");
$this->helper = new FirewallHelper(); $this->helper = new FirewallHelper();
} }
final protected function getModel(): FirewallModel final protected function getModel(): FirewallModel
@ -31,12 +28,12 @@ class FirewallController extends CloudflareController
} }
return $this->model; return $this->model;
} }
final protected function getMyLibrary(): Firewall protected function getService(): FirewallService
{ {
if (!isset($this->_myLibrays[$this->_zone_entity->getPK()])) { if ($this->service === null) {
$this->_myLibrays[$this->_zone_entity->getPK()] = new Firewall($this->_zone_entity); $this->service = new FirewallService();
} }
return $this->_myLibrays[$this->_zone_entity->getPK()]; return $this->service;
} }
protected function getFormFieldOption(string $field, array $options = []): array protected function getFormFieldOption(string $field, array $options = []): array
{ {
@ -77,7 +74,7 @@ class FirewallController extends CloudflareController
//부모데이터정의 //부모데이터정의
$this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->entity->getParent()); $this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->entity->getParent());
//Socket처리 //Socket처리
$this->entity = $this->getMyLibrary()->modify($this->entity, $this->formDatas); $this->entity = $this->getService()->modify($this->_zone_entity, $this->entity, $this->formDatas);
} }
//View //View
//create_process_result에서 결과값을 entitys에 저장하고 호출하기때문에 아래와 같이 처리함 //create_process_result에서 결과값을 entitys에 저장하고 호출하기때문에 아래와 같이 처리함
@ -131,11 +128,12 @@ class FirewallController extends CloudflareController
//reload Firewall By Zone //reload Firewall By Zone
protected function reload_process(mixed $uid): void protected function reload_process(mixed $uid): void
{ {
//부모데이터정의
$this->_zone_entity = $this->getZoneModel()->getEntityByPK($uid); $this->_zone_entity = $this->getZoneModel()->getEntityByPK($uid);
if ($this->_zone_entity === null) { if ($this->_zone_entity === null) {
throw new \Exception("Zone: {$uid} 정보를 찾을수 없습니다."); throw new \Exception("Zone: {$uid} 정보를 찾을수 없습니다.");
} }
$this->getMyLibrary()->reload(); $this->getService()->reload($this->_zone_entity);
} }
public function reload(string $uid): RedirectResponse public function reload(string $uid): RedirectResponse
{ {

View File

@ -9,19 +9,16 @@ use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use App\Helpers\Cloudflare\RecordHelper; use App\Helpers\Cloudflare\RecordHelper;
use App\Models\Cloudflare\RecordModel; use App\Models\Cloudflare\RecordModel;
use App\Services\Cloudflare\RecordService;
use App\Models\Cloudflare\ZoneModel; use App\Models\Cloudflare\ZoneModel;
use App\Services\Cloudflare\Record;
class RecordController extends CloudflareController class RecordController extends CloudflareController
{ {
private $_zone_entity = null; private $_zone_entity = null;
private $_myLibrays = [];
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->class_name .= "Record"; $this->title = lang("{$this->getService()->class_path}.title");
$this->class_path .= $this->class_name;
$this->title = lang("{$this->class_path}.title");
$this->helper = new RecordHelper(); $this->helper = new RecordHelper();
} }
final protected function getModel(): RecordModel final protected function getModel(): RecordModel
@ -31,12 +28,12 @@ class RecordController extends CloudflareController
} }
return $this->model; return $this->model;
} }
final protected function getMyLibrary(): Record protected function getService(): RecordService
{ {
if (!isset($this->_myLibrays[$this->_zone_entity->getPK()])) { if ($this->service === null) {
$this->_myLibrays[$this->_zone_entity->getPK()] = new Record($this->_zone_entity); $this->service = new RecordService();
} }
return $this->_myLibrays[$this->_zone_entity->getPK()]; return $this->service;
} }
protected function getFormFieldOption(string $field, array $options = []): array protected function getFormFieldOption(string $field, array $options = []): array
{ {
@ -122,7 +119,8 @@ class RecordController extends CloudflareController
//Socket처리 //Socket처리
$entitys = []; $entitys = [];
foreach ($this->formDatas['hosts'] as $host) { foreach ($this->formDatas['hosts'] as $host) {
$entity = $this->getMyLibrary()->create( $entity = $this->getService()->create(
$this->_zone_entity,
$host, $host,
$this->formDatas['type'], $this->formDatas['type'],
$this->formDatas['content'], $this->formDatas['content'],
@ -170,7 +168,7 @@ class RecordController extends CloudflareController
//부모데이터정의 //부모데이터정의
$this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->entity->getParent()); $this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->entity->getParent());
//Socket처리 //Socket처리
$this->entity = $this->getMyLibrary()->modify($this->entity, $this->formDatas); $this->entity = $this->getService()->modify($this->_zone_entity, $this->entity, $this->formDatas);
} }
} }
//일괄처리작업 //일괄처리작업
@ -198,7 +196,7 @@ class RecordController extends CloudflareController
//부모데이터정의 //부모데이터정의
$this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->entity->getParent()); $this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->entity->getParent());
//Cloudflare 삭제 //Cloudflare 삭제
$this->entity = $this->getMyLibrary()->delete($this->entity); $this->entity = $this->getService()->delete($this->_zone_entity, $this->entity);
} }
//리스트 //리스트
protected function list_entitys_process(): array protected function list_entitys_process(): array
@ -252,7 +250,7 @@ class RecordController extends CloudflareController
//부모데이터정의 //부모데이터정의
$this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->entity->getParent()); $this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->entity->getParent());
//Socket처리 //Socket처리
$this->entity = $this->getMyLibrary()->sync($this->entity); $this->entity = $this->getService()->sync($this->_zone_entity, $this->entity);
} }
public function sync(string $uid): RedirectResponse public function sync(string $uid): RedirectResponse
{ {
@ -261,11 +259,12 @@ class RecordController extends CloudflareController
//reload Record By Zone //reload Record By Zone
protected function reload_process(mixed $uid): void protected function reload_process(mixed $uid): void
{ {
//부모데이터정의
$this->_zone_entity = $this->getZoneModel()->getEntityByPK($uid); $this->_zone_entity = $this->getZoneModel()->getEntityByPK($uid);
if ($this->_zone_entity === null) { if ($this->_zone_entity === null) {
throw new \Exception("Zone: {$uid} 정보를 찾을수 없습니다."); throw new \Exception("Zone: {$uid} 정보를 찾을수 없습니다.");
} }
$this->getMyLibrary()->reload(); $this->getService()->reload($this->_zone_entity);
} }
public function reload(string $uid): RedirectResponse public function reload(string $uid): RedirectResponse
{ {

View File

@ -2,42 +2,39 @@
namespace App\Controllers\Admin\Cloudflare; namespace App\Controllers\Admin\Cloudflare;
use App\Helpers\Cloudflare\ZoneHelper;
use App\Models\Cloudflare\AccountModel;
use App\Models\Cloudflare\ZoneModel;
use App\Services\Cloudflare\RecordService;
use App\Services\Cloudflare\ZoneService;
use CodeIgniter\HTTP\DownloadResponse; use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use App\Helpers\Cloudflare\ZoneHelper;
use App\Models\Cloudflare\AccountModel;
use App\Models\Cloudflare\ZoneModel;
use App\Services\Cloudflare\Record;
use App\Services\Cloudflare\Zone;
class ZoneController extends CloudflareController class ZoneController extends CloudflareController
{ {
private $_account_entity = null; private $_account_entity = null;
private $_myLibrays = [];
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->class_name .= "Zone"; $this->title = lang("{$this->getService()->class_path}.title");;
$this->class_path .= $this->class_name;
$this->title = lang("{$this->class_path}.title");
$this->helper = new ZoneHelper(); $this->helper = new ZoneHelper();
} }
final protected function getModel(): ZoneModel protected function getModel(): ZoneModel
{ {
if ($this->model === null) { if ($this->_model === null) {
$this->model = new ZoneModel(); $this->_model = new ZoneModel();
} }
return $this->model; return $this->_model;
} }
final protected function getMyLibrary(): Zone protected function getService(): ZoneService
{ {
if (!isset($this->_myLibrays[$this->_account_entity->getPK()])) { if ($this->service === null) {
$this->_myLibrays[$this->_account_entity->getPK()] = new Zone($this->_account_entity); $this->service = new ZoneService();
} }
return $this->_myLibrays[$this->_account_entity->getPK()]; return $this->service;
} }
protected function getFormFieldOption(string $field, array $options = []): array protected function getFormFieldOption(string $field, array $options = []): array
{ {
@ -148,7 +145,7 @@ class ZoneController extends CloudflareController
$cnt = 1; $cnt = 1;
$zone_entitys = []; $zone_entitys = [];
foreach ($this->formDatas['domains'] as $domain) { foreach ($this->formDatas['domains'] as $domain) {
$entity = $this->getMyLibrary()->create($domain); $entity = $this->getService()->create($this->_account_entity, $domain);
log_message("debug", "Zone:{$entity->getTitle()} 작업을 완료하였습니다."); log_message("debug", "Zone:{$entity->getTitle()} 작업을 완료하였습니다.");
$zone_entitys[] = $entity; $zone_entitys[] = $entity;
$cnt++; $cnt++;
@ -156,10 +153,11 @@ class ZoneController extends CloudflareController
//Record생성 //Record생성
$entitys = []; $entitys = [];
foreach ($zone_entitys as $zone_entity) { foreach ($zone_entitys as $zone_entity) {
$record = new Record($zone_entity); $record = new RecordService();
$record_entitys = []; $record_entitys = [];
foreach ($this->formDatas['hosts'] as $host) { foreach ($this->formDatas['hosts'] as $host) {
$entity = $record->create( $entity = $record->create(
$zone_entity,
$host, $host,
$this->formDatas['type'], $this->formDatas['type'],
$this->formDatas['content'], $this->formDatas['content'],
@ -205,7 +203,7 @@ class ZoneController extends CloudflareController
//부모데이터정의 //부모데이터정의
$this->_account_entity = $this->getAccountModel()->getEntityByPK($this->entity->getParent()); $this->_account_entity = $this->getAccountModel()->getEntityByPK($this->entity->getParent());
//Socket처리 //Socket처리
$this->entity = $this->getMyLibrary()->modify($this->entity, $this->formDatas); $this->entity = $this->getService()->modify($this->_account_entity, $this->entity, $this->formDatas);
} }
//일괄처리작업 //일괄처리작업
public function batcjob(): RedirectResponse public function batcjob(): RedirectResponse
@ -233,13 +231,13 @@ class ZoneController extends CloudflareController
//Record부터 삭제필요 //Record부터 삭제필요
$this->getRecordModel()->where($this->getRecordModel()::PARENT, $this->entity->getPK()); $this->getRecordModel()->where($this->getRecordModel()::PARENT, $this->entity->getPK());
foreach ($this->getRecordModel()->getEntitys() as $record_entity) { foreach ($this->getRecordModel()->getEntitys() as $record_entity) {
$record = new Record($this->entity); $record = new RecordService();
$record->delete($record_entity); $record->delete($this->entity, $record_entity);
} }
//Zone 삭제 //Zone 삭제
//부모데이터정의 //부모데이터정의
$this->_account_entity = $this->getAccountModel()->getEntityByPK($this->entity->getParent()); $this->_account_entity = $this->getAccountModel()->getEntityByPK($this->entity->getParent());
$this->entity = $this->getMyLibrary()->delete($this->entity); $this->entity = $this->getService()->delete($this->_account_entity, $this->entity);
} }
// 리스트 // 리스트
protected function list_entitys_process(): array protected function list_entitys_process(): array
@ -293,7 +291,7 @@ class ZoneController extends CloudflareController
//부모데이터정의 //부모데이터정의
$this->_account_entity = $this->getAccountModel()->getEntityByPK($this->entity->getParent()); $this->_account_entity = $this->getAccountModel()->getEntityByPK($this->entity->getParent());
//Socket처리 //Socket처리
$this->entity = $this->getMyLibrary()->sync($this->entity); $this->entity = $this->getService()->sync($this->_account_entity, $this->entity);
} }
public function sync(string $uid): RedirectResponse public function sync(string $uid): RedirectResponse
{ {
@ -302,11 +300,12 @@ class ZoneController extends CloudflareController
//reload Zone By Account //reload Zone By Account
protected function reload_process(mixed $uid): void protected function reload_process(mixed $uid): void
{ {
//부모데이터정의
$this->_account_entity = $this->getAccountModel()->getEntityByPK($uid); $this->_account_entity = $this->getAccountModel()->getEntityByPK($uid);
if ($this->_account_entity === null) { if ($this->_account_entity === null) {
throw new \Exception("Account: {$uid} 정보를 찾을수 없습니다."); throw new \Exception("Account: {$uid} 정보를 찾을수 없습니다.");
} }
$this->getMyLibrary()->reload(); $this->getService()->reload($this->_account_entity);
} }
public function reload(string $uid): RedirectResponse public function reload(string $uid): RedirectResponse
{ {

View File

@ -2,24 +2,23 @@
namespace App\Controllers\Admin; namespace App\Controllers\Admin;
use App\Controllers\CommonController;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use App\Helpers\CommonHelper; use App\Helpers\CommonHelper;
use App\Controllers\Admin\AdminController;
class Home extends AdminController class Home extends CommonController
{ {
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->title = "Main"; $this->layout = "admin";
$this->uri_path = "admin/";
$this->view_path = "admin/";
$this->title = "관리자페이지 메인";
$this->helper = new CommonHelper(); $this->helper = new CommonHelper();
} }
protected function getModel(): mixed
{
return null;
}
public function index(): string public function index(): string
{ {
helper(['form']); helper(['form']);

View File

@ -4,7 +4,7 @@ namespace App\Controllers\Admin;
use App\Helpers\MapurlHelper; use App\Helpers\MapurlHelper;
use App\Models\MapurlModel; use App\Models\MapurlModel;
use App\Services\MapurlService;
use CodeIgniter\HTTP\DownloadResponse; use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
@ -16,17 +16,23 @@ class MapurlController extends AdminController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->class_name .= "Mapurl"; $this->title = lang("{$this->getService()->class_path}.title");
$this->class_path .= $this->class_name;
$this->title = lang("{$this->class_path}.title");
$this->helper = new MapurlHelper(); $this->helper = new MapurlHelper();
} }
protected function getModel(): MapurlModel protected function getModel(): MapurlModel
{ {
if ($this->model === null) { if ($this->_model === null) {
$this->model = new MapurlModel(); $this->_model = new MapurlModel();
} }
return $this->model; return $this->_model;
}
protected function getService(): MapurlService
{
if ($this->service === null) {
$this->service = new MapurlService();
}
return $this->service;
} }
private function init(string $action, array $fields = []): void private function init(string $action, array $fields = []): void
{ {

View File

@ -4,7 +4,7 @@ namespace App\Controllers\Admin;
use App\Helpers\UserHelper; use App\Helpers\UserHelper;
use App\Models\UserModel; use App\Models\UserModel;
use App\Services\UserService;
use CodeIgniter\HTTP\DownloadResponse; use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
@ -12,22 +12,28 @@ use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Validation\Validation; use CodeIgniter\Validation\Validation;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
class UserController extends AdminController class UserController extends AdminController
{ {
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->class_name = "User"; $this->title = lang("{$this->getService()->class_path}.title");
$this->class_path .= $this->class_name;
$this->title = lang("{$this->class_path}.title");
$this->helper = new UserHelper(); $this->helper = new UserHelper();
} }
protected function getModel(): UserModel protected function getModel(): UserModel
{ {
if ($this->model === null) { if ($this->_model === null) {
$this->model = new UserModel(); $this->_model = new UserModel();
} }
return $this->model; return $this->_model;
}
protected function getService(): UserService
{
if ($this->service === null) {
$this->service = new UserService();
}
return $this->service;
} }
protected function setValidationRule($field, Validation $validation, string $action): Validation protected function setValidationRule($field, Validation $validation, string $action): Validation
{ {
@ -74,6 +80,7 @@ class UserController extends AdminController
{ {
$this->action = $action; $this->action = $action;
$this->fields = count($fields) ? $fields : ['id', $this->getModel()::TITLE, 'email', 'mobile', 'role', 'updated_at', 'created_at']; $this->fields = count($fields) ? $fields : ['id', $this->getModel()::TITLE, 'email', 'mobile', 'role', 'updated_at', 'created_at'];
$this->field_rules = $this->getModel()->getFieldRules($action, $this->fields);
$this->filter_fields = ['role', 'status']; $this->filter_fields = ['role', 'status'];
$this->field_options = $this->getFormFieldOptions($this->filter_fields); $this->field_options = $this->getFormFieldOptions($this->filter_fields);
$this->batchjob_fields = ['status']; $this->batchjob_fields = ['status'];

View File

@ -2,33 +2,37 @@
namespace App\Controllers\Admin; namespace App\Controllers\Admin;
use App\Helpers\UserSNSHelper;
use App\Models\UserModel;
use App\Models\UserSNSModel;
use CodeIgniter\HTTP\DownloadResponse; use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Validation\Validation;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use App\Helpers\UserSNSHelper;
use App\Models\UserModel;
use App\Models\UserSNSModel;
use App\Services\UserSNSService;
class UserSNSController extends AdminController class UserSNSController extends AdminController
{ {
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->class_name = "UserSNS"; $this->title = lang("{$this->getService()->class_path}.title");
$this->class_path .= $this->class_name;
$this->title = lang("{$this->class_path}.title");
$this->helper = new UserSNSHelper(); $this->helper = new UserSNSHelper();
} }
protected function getModel(): UserSNSModel protected function getModel(): UserSNSModel
{ {
if ($this->model === null) { if ($this->_model === null) {
$this->model = new UserSNSModel(); $this->_model = new UserSNSModel();
} }
return $this->model; return $this->_model;
}
protected function getService(): UserSNSService
{
if ($this->service === null) {
$this->service = new UserSNSService();
}
return $this->service;
} }
protected function getFormFieldOption(string $field, array $options = []): array protected function getFormFieldOption(string $field, array $options = []): array
{ {

View File

@ -7,9 +7,9 @@ use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use App\Models\UserModel; use App\Models\UserModel;
use App\Helpers\UserHelper; use App\Services\UserService;
use App\Helpers\Cloudflare\AuthHelper;
use App\Libraries\MyAuth\GoogleAuth; use App\Libraries\MyAuth\GoogleAuth;
use App\Libraries\MyAuth\LocalAuth; use App\Libraries\MyAuth\LocalAuth;
@ -18,17 +18,22 @@ class AuthController extends MVController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->class_name .= "User"; $this->title = lang("{$this->getService()->class_path}.title");;
$this->class_path .= $this->class_name; $this->helper = new AuthHelper();
$this->title = lang("{$this->class_path}.title");
$this->helper = new UserHelper();
} }
protected function getModel(): UserModel protected function getModel(): UserModel
{ {
if ($this->model === null) { if ($this->_model === null) {
$this->model = new UserModel(); $this->_model = new UserModel();
} }
return $this->model; return $this->_model;
}
protected function getService(): UserService
{
if ($this->service === null) {
$this->service = new UserService();
}
return $this->service;
} }
private function init(string $action, array $fields = []): void private function init(string $action, array $fields = []): void
{ {

View File

@ -6,10 +6,10 @@ use App\Controllers\BaseController;
use App\Entities\Cloudflare\AccountEntity; use App\Entities\Cloudflare\AccountEntity;
use App\Entities\Cloudflare\AuthEntity; use App\Entities\Cloudflare\AuthEntity;
use App\Entities\Cloudflare\ZoneEntity; use App\Entities\Cloudflare\ZoneEntity;
use App\Services\Cloudflare\Account; use App\Services\Cloudflare\AccountService;
use App\Services\Cloudflare\Zone; use App\Services\Cloudflare\ZoneService;
use App\Services\Cloudflare\Record; use App\Services\Cloudflare\RecordService;
use App\Services\Cloudflare\Firewall; use App\Services\Cloudflare\FirewallService;
use App\Models\Cloudflare\AuthModel; use App\Models\Cloudflare\AuthModel;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
@ -37,23 +37,23 @@ class Cloudflare extends BaseController
} }
private function account_process(AuthEntity $auth_entity): array private function account_process(AuthEntity $auth_entity): array
{ {
$account = new Account($auth_entity); $account = new AccountService();
return $account->reload(); return $account->reload($auth_entity);
} }
private function zone_process(AccountEntity $account_entity): array private function zone_process(AccountEntity $account_entity): array
{ {
$zone = new Zone($account_entity); $zone = new ZoneService();
return $zone->reload(); return $zone->reload($account_entity);
} }
private function record_process(ZoneEntity $zone_entity): array private function record_process(ZoneEntity $zone_entity): array
{ {
$record = new Record($zone_entity); $record = new RecordService();
return $record->reload(); return $record->reload($zone_entity);
} }
private function firewall_process(ZoneEntity $zone_entity): array private function firewall_process(ZoneEntity $zone_entity): array
{ {
$firewall = new Firewall($zone_entity); $firewall = new FirewallService();
return $firewall->reload(); return $firewall->reload($zone_entity);
} }
public function reload(mixed $uid = false): void public function reload(mixed $uid = false): void
{ {

View File

@ -3,7 +3,6 @@
namespace App\Controllers\Cloudflare; namespace App\Controllers\Cloudflare;
use App\Controllers\MVController; use App\Controllers\MVController;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -21,8 +20,6 @@ abstract class CloudflareController extends MVController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->class_path = "Cloudflare/";
$this->uri_path .= strtolower($this->class_path);
} }
final protected function getAuthModel(): AuthModel final protected function getAuthModel(): AuthModel
{ {
@ -60,18 +57,18 @@ abstract class CloudflareController extends MVController
final protected function trigger_procedure(): ResponseInterface final protected function trigger_procedure(): ResponseInterface
{ {
//Transaction Start //Transaction Start
$this->getModel()->transStart(); $this->getService()->getModel()->transStart();
try { try {
// 여기에 필요한 로직을 구현하세요 // 여기에 필요한 로직을 구현하세요
log_message("debug", var_export($this->request->getVar(), true)); log_message("debug", var_export($this->request->getVar(), true));
$this->trigger_process(); $this->trigger_process();
$this->message = "{$this->class_name}: Trigger 작업이 완료되었습니다."; $this->message = "{$this->class_name}: Trigger 작업이 완료되었습니다.";
$this->getModel()->transCommit(); $this->getService()->getModel()->transCommit();
log_message("notice", __FUNCTION__ . $this->message); log_message("notice", __FUNCTION__ . $this->message);
return $this->response->setJSON(['status' => 200, $this->message], 200); return $this->response->setJSON(['status' => 200, $this->message], 200);
} catch (\Exception $e) { } catch (\Exception $e) {
//Transaction Rollback //Transaction Rollback
$this->getModel()->transRollback(); $this->getService()->getModel()->transRollback();
log_message("error", $e->getMessage()); log_message("error", $e->getMessage());
return $this->response->setJSON(['status' => 500, 'message' => $e->getMessage()], 500); return $this->response->setJSON(['status' => 500, 'message' => $e->getMessage()], 500);
} }

View File

@ -6,18 +6,14 @@ use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use App\Models\Cloudflare\FirewallModel; use App\Models\Cloudflare\FirewallModel;
use App\Services\Cloudflare\Firewall; use App\Services\Cloudflare\FirewallService;
class FirewallController extends CloudflareController class FirewallController extends CloudflareController
{ {
private $_zone_entity = null; private $_zone_entity = null;
private $_myLibrays = [];
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->class_name .= "Firewall";
$this->class_path .= $this->class_name;
$this->title = lang("{$this->class_path}.title");
} }
final protected function getModel(): FirewallModel final protected function getModel(): FirewallModel
{ {
@ -26,12 +22,12 @@ class FirewallController extends CloudflareController
} }
return $this->model; return $this->model;
} }
final protected function getMyLibrary(): Firewall protected function getService(): FirewallService
{ {
if (!isset($this->_myLibrays[$this->_zone_entity->getPK()])) { if ($this->service === null) {
$this->_myLibrays[$this->_zone_entity->getPK()] = new Firewall($this->_zone_entity); $this->service = new FirewallService();
} }
return $this->_myLibrays[$this->_zone_entity->getPK()]; return $this->service;
} }
//Trigger작업 //Trigger작업
protected function trigger_process(): void protected function trigger_process(): void

View File

@ -6,18 +6,14 @@ use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use App\Models\Cloudflare\RecordModel; use App\Models\Cloudflare\RecordModel;
use App\Services\Cloudflare\Record; use App\Services\Cloudflare\RecordService;
class RecordController extends CloudflareController class RecordController extends CloudflareController
{ {
private $_zone_entity = null; private $_zone_entity = null;
private $_myLibrays = [];
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->class_name .= "Record";
$this->class_path .= $this->class_name;
$this->title = lang("{$this->class_path}.title");
} }
final protected function getModel(): RecordModel final protected function getModel(): RecordModel
{ {
@ -26,12 +22,12 @@ class RecordController extends CloudflareController
} }
return $this->model; return $this->model;
} }
final protected function getMyLibrary(): Record protected function getService(): RecordService
{ {
if (!isset($this->_myLibrays[$this->_zone_entity->getPK()])) { if ($this->service === null) {
$this->_myLibrays[$this->_zone_entity->getPK()] = new Record($this->_zone_entity); $this->service = new RecordService();
} }
return $this->_myLibrays[$this->_zone_entity->getPK()]; return $this->service;
} }
//Trigger작업 //Trigger작업
protected function trigger_process(): void protected function trigger_process(): void

View File

@ -6,18 +6,14 @@ use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use App\Models\Cloudflare\ZoneModel; use App\Models\Cloudflare\ZoneModel;
use App\Services\Cloudflare\Zone; use App\Services\Cloudflare\ZoneService;
class ZoneController extends CloudflareController class ZoneController extends CloudflareController
{ {
private $_account_entity = null; private $_account_entity = null;
private $_myLibrays = [];
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->class_name .= "Zone";
$this->class_path .= $this->class_name;
$this->title = lang("{$this->class_path}.title");
} }
final protected function getModel(): ZoneModel final protected function getModel(): ZoneModel
{ {
@ -26,12 +22,12 @@ class ZoneController extends CloudflareController
} }
return $this->model; return $this->model;
} }
final protected function getMyLibrary(): Zone protected function getService(): ZoneService
{ {
if (!isset($this->_myLibrays[$this->_account_entity->getPK()])) { if ($this->service === null) {
$this->_myLibrays[$this->_account_entity->getPK()] = new Zone($this->_account_entity); $this->service = new ZoneService();
} }
return $this->_myLibrays[$this->_account_entity->getPK()]; return $this->service;
} }
//Trigger작업 //Trigger작업
protected function trigger_process(): void protected function trigger_process(): void

View File

@ -9,7 +9,7 @@ use Psr\Log\LoggerInterface;
abstract class CommonController extends BaseController abstract class CommonController extends BaseController
{ {
private $_viewDatas = []; private $_controlDatas = [];
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
@ -17,17 +17,17 @@ abstract class CommonController extends BaseController
} }
final public function __get($name) final public function __get($name)
{ {
if (!array_key_exists($name, $this->_viewDatas)) { if (!array_key_exists($name, $this->_controlDatas)) {
return null; return null;
} }
return $this->_viewDatas[$name]; return $this->_controlDatas[$name];
} }
final public function __set($name, $value): void final public function __set($name, $value): void
{ {
$this->_viewDatas[$name] = $value; $this->_controlDatas[$name] = $value;
} }
final public function getViewDatas(): array final public function getViewDatas(): array
{ {
return $this->_viewDatas; return $this->_controlDatas;
} }
} }

View File

@ -1,19 +0,0 @@
<?php
namespace App\Controllers\Front;
use App\Controllers\MVController;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
abstract class FrontController extends MVController
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->layout = "front";
$this->uri_path = "front/";
$this->view_path = "front/";
}
}

View File

@ -17,9 +17,10 @@ abstract class MVController extends CommonController
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->class_path = ""; $this->class_path = $this->getService()->class_path;
} }
abstract protected function getModel(): mixed; abstract protected function getModel(): mixed;
abstract protected function getService(): mixed;
//Field별 Form Rule용 //Field별 Form Rule용
protected function setValidationRule($field, Validation $validation, string $action): Validation protected function setValidationRule($field, Validation $validation, string $action): Validation
{ {
@ -42,8 +43,9 @@ abstract class MVController extends CommonController
{ {
switch ($field) { switch ($field) {
default: default:
// dd(lang($this->class_path . '.' . strtoupper($field))); // echo "TEST:" . $this->getService()->class_path . "," . $this->getService()->class_name;
$options[$field] = lang($this->class_path . '.' . strtoupper($field)); // dd(lang($this->getService()->class_path . '.' . strtoupper($field)));
$options[$field] = lang($this->getService()->class_path . '.' . strtoupper($field));
break; break;
} }
return $options; return $options;
@ -56,7 +58,6 @@ abstract class MVController extends CommonController
} }
$options = $this->getFormFieldOption($field, $options); $options = $this->getFormFieldOption($field, $options);
} }
// dd($options);
return $options; return $options;
} }
//전송된 데이터 //전송된 데이터
@ -77,9 +78,7 @@ abstract class MVController extends CommonController
return $formDatas; return $formDatas;
} }
// 생성 // 생성
protected function create_form_process(): void protected function create_form_process(): void {}
{
}
final protected function create_form_procedure(): RedirectResponse|string final protected function create_form_procedure(): RedirectResponse|string
{ {
try { try {
@ -100,7 +99,7 @@ abstract class MVController extends CommonController
//변경할 값 확인 : Upload된 파일 검증시 $this->request->getPOST()보다 먼처 체크필요 //변경할 값 확인 : Upload된 파일 검증시 $this->request->getPOST()보다 먼처 체크필요
$validation = $this->getValidation($fields, service('validation'), $action); $validation = $this->getValidation($fields, service('validation'), $action);
if (!$validation->withRequest($this->request)->run()) { if (!$validation->withRequest($this->request)->run()) {
throw new \Exception("{$this->class_name} 작업 데이터 검증 오류발생\n" . implode( throw new \Exception("{$this->getService()->class_name} 작업 데이터 검증 오류발생\n" . implode(
"\n", "\n",
$validation->getErrors() $validation->getErrors()
)); ));
@ -110,11 +109,11 @@ abstract class MVController extends CommonController
{ {
$this->create_validate($this->action, $this->fields); $this->create_validate($this->action, $this->fields);
$this->formDatas = $this->getFormDatas(); $this->formDatas = $this->getFormDatas();
$this->entity = $this->getModel()->create($this->formDatas); $this->entity = $this->getService()->create($this->formDatas);
} }
protected function create_process_result(): RedirectResponse|string protected function create_process_result(): RedirectResponse|string
{ {
$url = strtolower(base_url() . $this->uri_path . $this->class_name) . "/view/" . $this->entity->getPK(); $url = strtolower(base_url() . $this->uri_path . $this->getService()->class_name) . "/view/" . $this->entity->getPK();
return redirect()->to($url)->with('error', $this->message); return redirect()->to($url)->with('error', $this->message);
} }
final protected function create_procedure(): RedirectResponse|string final protected function create_procedure(): RedirectResponse|string
@ -125,7 +124,7 @@ abstract class MVController extends CommonController
helper(['form']); helper(['form']);
$this->create_process(); $this->create_process();
$this->getModel()->transCommit(); $this->getModel()->transCommit();
$this->message = "{$this->class_name} : 생성작업이 완료되었습니다."; $this->message = "{$this->getService()->class_name} : 생성작업이 완료되었습니다.";
log_message("notice", $this->message); log_message("notice", $this->message);
return $this->create_process_result(); return $this->create_process_result();
} catch (\Exception $e) { } catch (\Exception $e) {
@ -163,7 +162,7 @@ abstract class MVController extends CommonController
//변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요 //변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요
$validation = $this->getValidation($fields, service('validation'), $action); $validation = $this->getValidation($fields, service('validation'), $action);
if (!$validation->withRequest($this->request)->run()) { if (!$validation->withRequest($this->request)->run()) {
throw new \Exception("{$this->class_name} 작업 데이터 검증 오류발생\n" . implode( throw new \Exception("{$this->getService()->class_name} 작업 데이터 검증 오류발생\n" . implode(
"\n", "\n",
$validation->getErrors() $validation->getErrors()
)); ));
@ -178,11 +177,11 @@ abstract class MVController extends CommonController
if ($this->entity === null) { if ($this->entity === null) {
throw new \Exception(__FUNCTION__ . " => {$uid} 정보를 찾을수 없습니다."); throw new \Exception(__FUNCTION__ . " => {$uid} 정보를 찾을수 없습니다.");
} }
$this->entity = $this->getModel()->modify($this->entity, $this->formDatas); $this->entity = $this->getService()->modify($this->entity, $this->formDatas);
} }
protected function modify_process_result(): RedirectResponse|string protected function modify_process_result(): RedirectResponse|string
{ {
$url = strtolower(base_url() . $this->uri_path . $this->class_name) . "/view/" . $this->entity->getPK(); $url = strtolower(base_url() . $this->uri_path . $this->getService()->class_name) . "/view/" . $this->entity->getPK();
return redirect()->to($url)->with('error', $this->message); return redirect()->to($url)->with('error', $this->message);
} }
final protected function modify_procedure(mixed $uid): RedirectResponse|string final protected function modify_procedure(mixed $uid): RedirectResponse|string
@ -193,7 +192,7 @@ abstract class MVController extends CommonController
helper(['form']); helper(['form']);
$this->modify_process($uid); $this->modify_process($uid);
$this->getModel()->transCommit(); $this->getModel()->transCommit();
$this->message = "{$this->class_name} : 수정작업이 완료되었습니다."; $this->message = "{$this->getService()->class_name} : 수정작업이 완료되었습니다.";
log_message("notice", $this->message); log_message("notice", $this->message);
return $this->modify_process_result(); return $this->modify_process_result();
} catch (\Exception $e) { } catch (\Exception $e) {
@ -226,7 +225,7 @@ abstract class MVController extends CommonController
$this->modify_process($uid); $this->modify_process($uid);
} }
$this->getModel()->transCommit(); $this->getModel()->transCommit();
$this->message = "{$this->class_name} : 일괄처리작업이 완료되었습니다."; $this->message = "{$this->getService()->class_name} : 일괄처리작업이 완료되었습니다.";
log_message("notice", $this->message); log_message("notice", $this->message);
// 이전 URL로 리다이렉트 // 이전 URL로 리다이렉트
return redirect()->to($this->myauth->popPreviousUrl())->with('error', $this->message); return redirect()->to($this->myauth->popPreviousUrl())->with('error', $this->message);
@ -247,7 +246,7 @@ abstract class MVController extends CommonController
$this->fields = [$field]; $this->fields = [$field];
$this->modify_process($uid); $this->modify_process($uid);
$this->getModel()->transCommit(); $this->getModel()->transCommit();
$this->message = "{$this->class_name} : 단일필드작업이 완료되었습니다."; $this->message = "{$this->getService()->class_name} : 단일필드작업이 완료되었습니다.";
log_message("notice", $this->message); log_message("notice", $this->message);
// 이전 URL로 리다이렉트 // 이전 URL로 리다이렉트
return redirect()->to($this->myauth->popPreviousUrl())->with('error', $this->message); return redirect()->to($this->myauth->popPreviousUrl())->with('error', $this->message);
@ -294,7 +293,7 @@ abstract class MVController extends CommonController
if ($this->entity === null) { if ($this->entity === null) {
throw new \Exception("{$uid} 정보를 찾을수 없습니다."); throw new \Exception("{$uid} 정보를 찾을수 없습니다.");
} }
$this->entity = $this->getModel()->delete($this->entity->getPK()); $this->entity = $this->getService()->delete($this->entity->getPK());
} }
final public function delete(mixed $uid): RedirectResponse final public function delete(mixed $uid): RedirectResponse
{ {
@ -303,7 +302,7 @@ abstract class MVController extends CommonController
try { try {
$this->delete_process($uid); $this->delete_process($uid);
$this->getModel()->transCommit(); $this->getModel()->transCommit();
$this->message = "{$this->class_name} : 삭제작업이 완료되었습니다."; $this->message = "{$this->getService()->class_name} : 삭제작업이 완료되었습니다.";
log_message("notice", $this->message); log_message("notice", $this->message);
// 이전 URL로 리다이렉트 // 이전 URL로 리다이렉트
return redirect()->to($this->myauth->popPreviousUrl())->with('error', $this->message); return redirect()->to($this->myauth->popPreviousUrl())->with('error', $this->message);
@ -329,7 +328,7 @@ abstract class MVController extends CommonController
$this->delete_process($uid); $this->delete_process($uid);
} }
$this->getModel()->transCommit(); $this->getModel()->transCommit();
$this->message = "{$this->class_name} : 일괄삭제처리작업이 완료되었습니다."; $this->message = "{$this->getService()->class_name} : 일괄삭제처리작업이 완료되었습니다.";
log_message("notice", $this->message); log_message("notice", $this->message);
// 이전 URL로 리다이렉트 // 이전 URL로 리다이렉트
return redirect()->to($this->myauth->popPreviousUrl())->with('error', $this->message); return redirect()->to($this->myauth->popPreviousUrl())->with('error', $this->message);
@ -441,12 +440,12 @@ abstract class MVController extends CommonController
$full_path = WRITEPATH . DIRECTORY_SEPARATOR . "excel"; $full_path = WRITEPATH . DIRECTORY_SEPARATOR . "excel";
switch ($document_type) { switch ($document_type) {
case 'excel': case 'excel':
$file_name = sprintf("%s_%s.xlsx", $this->class_name, date('Y-m-d_Hm')); $file_name = sprintf("%s_%s.xlsx", $this->getService()->class_name, date('Y-m-d_Hm'));
$writer = IOFactory::createWriter($loaded_data, 'Xlsx'); $writer = IOFactory::createWriter($loaded_data, 'Xlsx');
$writer->save($full_path . DIRECTORY_SEPARATOR . $file_name); $writer->save($full_path . DIRECTORY_SEPARATOR . $file_name);
break; break;
case 'pdf': case 'pdf':
$file_name = sprintf("%s_%s.pdf", $this->class_name, date('Y-m-d_Hm')); $file_name = sprintf("%s_%s.pdf", $this->getService()->class_name, date('Y-m-d_Hm'));
$writer = new Mpdf($loaded_data); $writer = new Mpdf($loaded_data);
$writer->save($full_path . DIRECTORY_SEPARATOR . $file_name); $writer->save($full_path . DIRECTORY_SEPARATOR . $file_name);
break; break;

View File

@ -15,7 +15,7 @@ class AccountHelper extends MVCHelper
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{ {
if (in_array($viewDatas['action'], ['create', 'modify'])) { if (in_array($viewDatas['action'], ['create', 'modify'])) {
$extras = (strpos($viewDatas['model']->getFieldRule($viewDatas['action'], $field), 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras]; $extras = (strpos($viewDatas['field_rules'][$field], 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras];
} }
$value = $value ?: DEFAULTS['EMPTY']; $value = $value ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
@ -68,22 +68,33 @@ class AccountHelper extends MVCHelper
$this->old_parent = $viewDatas['entity']->getParent(); $this->old_parent = $viewDatas['entity']->getParent();
break; break;
case AccountModel::TITLE: case AccountModel::TITLE:
$value = anchor( $reload = anchor(
base_url() . $viewDatas['uri_path'] . 'zone/reload/' . $viewDatas['entity']->getPK(), base_url() . $viewDatas['uri_path'] . 'zone/reload/' . $viewDatas['entity']->getPK(),
ICONS["RELOAD"], ICONS["RELOAD"],
[ [
"class" => "btn btn-sm btn-primary btn-circle", "class" => "btn btn-sm btn-primary btn-circle",
"target" => "_self", "target" => "_self",
] ]
) . " " . );
anchor( $flag = anchor(
base_url() . $viewDatas['uri_path'] . "zone?account_uid=" . $viewDatas['entity']->getPK(), base_url() . $viewDatas['uri_path'] . "zone?account_uid=" . $viewDatas['entity']->getPK(),
ICONS["FLAG"], ICONS["FLAG"],
[ [
"class" => "btn btn-sm btn-primary btn-circle", "class" => "btn btn-sm btn-primary btn-circle",
"target" => "_self", "target" => "_self",
] ]
) . " " . parent::getFieldView($field, $viewDatas, $extras); );
$value = $reload . " " . $flag . " " . form_label(
$value,
'view',
[
"data-src" => current_url() . '/view/' . $viewDatas['entity']->getPK(),
"data-bs-toggle" => "modal",
"data-bs-target" => "#index_action_form",
"style" => "color: blue; cursor: pointer; font-weight:bold;",
...$extras,
]
);
break; break;
case 'type': case 'type':
case 'status': case 'status':

View File

@ -14,7 +14,7 @@ class AuthHelper extends MVCHelper
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{ {
if (in_array($viewDatas['action'], ['create', 'modify'])) { if (in_array($viewDatas['action'], ['create', 'modify'])) {
$extras = (strpos($viewDatas['model']->getFieldRule($viewDatas['action'], $field), 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras]; $extras = (strpos($viewDatas['field_rules'][$field], 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras];
} }
$value = $value ?: DEFAULTS['EMPTY']; $value = $value ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
@ -32,22 +32,33 @@ class AuthHelper extends MVCHelper
$value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY']; $value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
case AuthModel::TITLE: case AuthModel::TITLE:
$value = anchor( $reload = anchor(
base_url() . $viewDatas['uri_path'] . 'account/reload/' . $viewDatas['entity']->getPK(), base_url() . $viewDatas['uri_path'] . 'account/reload/' . $viewDatas['entity']->getPK(),
ICONS["RELOAD"], ICONS["RELOAD"],
[ [
"class" => "btn btn-sm btn-primary btn-circle", "class" => "btn btn-sm btn-primary btn-circle",
"target" => "_self" "target" => "_self"
] ]
) . " " . );
anchor( $flag = anchor(
base_url() . $viewDatas['uri_path'] . "account?auth_uid=" . $viewDatas['entity']->getPK(), base_url() . $viewDatas['uri_path'] . "account?auth_uid=" . $viewDatas['entity']->getPK(),
ICONS["FLAG"], ICONS["FLAG"],
[ [
"class" => "btn btn-sm btn-primary btn-circle", "class" => "btn btn-sm btn-primary btn-circle ms1",
"target" => "_self" "target" => "_self"
] ]
) . " " . parent::getFieldView($field, $viewDatas, $extras); );
$value = $reload . " " . $flag . " " . form_label(
$value,
'view',
[
"data-src" => current_url() . '/view/' . $viewDatas['entity']->getPK(),
"data-bs-toggle" => "modal",
"data-bs-target" => "#index_action_form",
"style" => "color: blue; cursor: pointer; font-weight:bold;",
...$extras,
]
);
break; break;
default: default:
$value = parent::getFieldView($field, $viewDatas, $extras); $value = parent::getFieldView($field, $viewDatas, $extras);

View File

@ -15,7 +15,7 @@ class FirewallHelper extends MVCHelper
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{ {
if (in_array($viewDatas['action'], ['create', 'modify'])) { if (in_array($viewDatas['action'], ['create', 'modify'])) {
$extras = (strpos($viewDatas['model']->getFieldRule($viewDatas['action'], $field), 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras]; $extras = (strpos($viewDatas['field_rules'][$field], 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras];
} }
$value = $value ?: DEFAULTS['EMPTY']; $value = $value ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
@ -76,7 +76,17 @@ class FirewallHelper extends MVCHelper
$this->old_parent = $viewDatas['entity']->getParent(); $this->old_parent = $viewDatas['entity']->getParent();
break; break;
case FirewallModel::TITLE: case FirewallModel::TITLE:
$value = parent::getFieldView($field, $viewDatas, ['class' => "label_hosts", ...$extras]); $value = form_label(
$value,
'view',
[
"data-src" => current_url() . '/view/' . $viewDatas['entity']->getPK(),
"data-bs-toggle" => "modal",
"data-bs-target" => "#index_action_form",
"style" => "color: blue; cursor: pointer; font-weight:bold;",
...$extras,
]
);
break; break;
case 'expression': case 'expression':
// 값이 40자 이상인 경우 자르고 '...' 추가 // 값이 40자 이상인 경우 자르고 '...' 추가

View File

@ -28,7 +28,7 @@ class RecordHelper extends MVCHelper
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{ {
if (in_array($viewDatas['action'], ['create', 'modify'])) { if (in_array($viewDatas['action'], ['create', 'modify'])) {
$extras = (strpos($viewDatas['model']->getFieldRule($viewDatas['action'], $field), 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras]; $extras = (strpos($viewDatas['field_rules'][$field], 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras];
} }
$value = $value ?: DEFAULTS['EMPTY']; $value = $value ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
@ -95,13 +95,23 @@ class RecordHelper extends MVCHelper
$this->old_parent = $viewDatas['entity']->getParent(); $this->old_parent = $viewDatas['entity']->getParent();
break; break;
case RecordModel::TITLE: case RecordModel::TITLE:
$value = parent::getFieldView($field, $viewDatas, ['class' => "label_hosts", ...$extras]);
$fixed = anchor( $fixed = anchor(
sprintf("%s/toggle/%s/fixed?fixed=%s", current_url(), $viewDatas['entity']->getPK(), $viewDatas['entity']->fixed == 'on' ? "off" : "on"), sprintf("%s/toggle/%s/fixed?fixed=%s", current_url(), $viewDatas['entity']->getPK(), $viewDatas['entity']->fixed == 'on' ? "off" : "on"),
$viewDatas['entity']->fixed == 'on' ? "<span class=\"text-danger\">" . ICONS['LOCK'] . "</span>" : ICONS['UNLOCK'], $viewDatas['entity']->fixed == 'on' ? "<span class=\"text-danger\">" . ICONS['LOCK'] . "</span>" : ICONS['UNLOCK'],
["class" => "ext-danger", "style" => "float:right;", ...$extras] ["class" => "ext-danger", "style" => "float:right;", ...$extras]
); );
$value = $fixed . " " . $value; $value = $fixed . " " . form_label(
$value,
'view',
[
"data-src" => current_url() . '/view/' . $viewDatas['entity']->getPK(),
"data-bs-toggle" => "modal",
"data-bs-target" => "#index_action_form",
'class' => "label_hosts",
"style" => "color: blue; cursor: pointer; font-weight:bold;",
...$extras,
]
);
break; break;
case 'content': case 'content':
// 값이 40자 이상인 경우 자르고 '...' 추가 // 값이 40자 이상인 경우 자르고 '...' 추가

View File

@ -15,7 +15,7 @@ class ZoneHelper extends MVCHelper
function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{ {
if (in_array($viewDatas['action'], ['create', 'modify'])) { if (in_array($viewDatas['action'], ['create', 'modify'])) {
$extras = (strpos($viewDatas['model']->getFieldRule($viewDatas['action'], $field), 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras]; $extras = (strpos($viewDatas['field_rules'][$field], 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras];
} }
$value = $value ?: DEFAULTS['EMPTY']; $value = $value ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
@ -91,31 +91,34 @@ class ZoneHelper extends MVCHelper
$this->old_parent = $viewDatas['entity']->getParent(); $this->old_parent = $viewDatas['entity']->getParent();
break; break;
case ZoneModel::TITLE: case ZoneModel::TITLE:
$record = anchor( $record_reload = anchor(
base_url() . $viewDatas['uri_path'] . 'record/reload/' . $viewDatas['entity']->getPK(), base_url() . $viewDatas['uri_path'] . 'record/reload/' . $viewDatas['entity']->getPK(),
ICONS["RELOAD"], ICONS["RELOAD"],
[ [
"class" => "btn btn-sm btn-primary btn-circle", "class" => "btn btn-sm btn-primary btn-circle",
"target" => "_self",
]
);
$record_flag = anchor(
base_url() . $viewDatas['uri_path'] . "record?zone_uid=" . $viewDatas['entity']->getPK(),
ICONS["FLAG"],
[
"class" => "btn btn-sm btn-outline-primary btn-circle",
"target" => "_self" "target" => "_self"
] ]
) . " " . );
anchor( $firewall_reload = "";
base_url() . $viewDatas['uri_path'] . "record?zone_uid=" . $viewDatas['entity']->getPK(), $firewall_flag = "";
ICONS["FLAG"], if (in_array($viewDatas['myauth']->getAuthInfo('id'), explode(",", env("cloudflare.firewall.acl")))) {
$firewall_reload = anchor(
base_url() . $viewDatas['uri_path'] . 'firewall/reload/' . $viewDatas['entity']->getPK(),
ICONS["RELOAD"],
[ [
"class" => "btn btn-sm btn-outline-primary btn-circle", "class" => "btn btn-sm btn-warning btn-circle",
"target" => "_self" "target" => "_self"
] ]
); );
$firewall = anchor( $firewall_flag = anchor(
base_url() . $viewDatas['uri_path'] . 'firewall/reload/' . $viewDatas['entity']->getPK(),
ICONS["RELOAD"],
[
"class" => "btn btn-sm btn-warning btn-circle",
"target" => "_self"
]
) . " " .
anchor(
base_url() . $viewDatas['uri_path'] . "firewall?zone_uid=" . $viewDatas['entity']->getPK(), base_url() . $viewDatas['uri_path'] . "firewall?zone_uid=" . $viewDatas['entity']->getPK(),
ICONS["FLAG"], ICONS["FLAG"],
[ [
@ -123,11 +126,24 @@ class ZoneHelper extends MVCHelper
"target" => "_self" "target" => "_self"
] ]
); );
}
$value = form_label(
$value,
'view',
[
"data-src" => current_url() . '/view/' . $viewDatas['entity']->getPK(),
"data-bs-toggle" => "modal",
"data-bs-target" => "#index_action_form",
'class' => "label_zones",
"style" => "color: blue; cursor: pointer; font-weight:bold;",
...$extras,
]
);
$value = sprintf( $value = sprintf(
"<table><tr><td style=\"padding-bottom:5px;\">%s</td><td rowspan=\"2\">%s</td></tr><tr><td>%s</td></tr></table>", "<table><tr><td style=\"padding-bottom:5px;\">%s</td><td rowspan=\"2\">%s</td></tr><tr><td>%s</td></tr></table>",
$record, $record_reload . " " . $record_flag,
parent::getFieldView($field, $viewDatas, ['class' => "label_zones", ...$extras]), $value,
(in_array($viewDatas['myauth']->getAuthInfo('id'), explode(",", env("cloudflare.firewall.acl")))) ? $firewall : "" $firewall_reload . " " . $firewall_flag
); );
break; break;
case 'name_servers': case 'name_servers':

View File

@ -12,9 +12,7 @@ abstract class MVCHelper extends CommonHelper
{ {
switch ($field) { switch ($field) {
default: default:
if (strpos($viewDatas['model']->getFieldRule($viewDatas['action'], $field), 'required') !== false) { $extras = (strpos($viewDatas['field_rules'][$field], 'required') !== false) ? ["class" => "text-danger", "required" => "", ...$extras] : $extras;
$extras = ["class" => "text-danger ", ...$extras];
}
$label = form_label(lang("{$viewDatas['class_path']}.label.{$field}"), $field, $extras); $label = form_label(lang("{$viewDatas['class_path']}.label.{$field}"), $field, $extras);
break; break;
} }
@ -24,7 +22,7 @@ abstract class MVCHelper extends CommonHelper
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{ {
if (in_array($viewDatas['action'], ['create', 'modify'])) { if (in_array($viewDatas['action'], ['create', 'modify'])) {
$extras = (strpos($viewDatas['model']->getFieldRule($viewDatas['action'], $field), 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras]; $extras = (strpos($viewDatas['field_rules'][$field], 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras];
} }
$value = $value ?: DEFAULTS['EMPTY']; $value = $value ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
@ -48,19 +46,6 @@ abstract class MVCHelper extends CommonHelper
{ {
$value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY']; $value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
case $viewDatas['model']::TITLE:
$value = form_label(
$value,
'view',
[
"data-src" => current_url() . '/view/' . $viewDatas['entity']->getPK(),
"data-bs-toggle" => "modal",
"data-bs-target" => "#index_action_form",
"style" => "color: blue; cursor: pointer; font-weight:bold;",
...$extras,
]
);
break;
case 'category_uid': case 'category_uid':
foreach (array_values($viewDatas['field_options'][$field]) as $category_2depths) { foreach (array_values($viewDatas['field_options'][$field]) as $category_2depths) {
foreach ($category_2depths as $key => $depth) { foreach ($category_2depths as $key => $depth) {

View File

@ -13,7 +13,7 @@ class MapurlHelper extends MVCHelper
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{ {
if (in_array($viewDatas['action'], ['create', 'modify'])) { if (in_array($viewDatas['action'], ['create', 'modify'])) {
$extras = (strpos($viewDatas['model']->getFieldRule($viewDatas['action'], $field), 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras]; $extras = (strpos($viewDatas['field_rules'][$field], 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras];
} }
$value = $value ?: DEFAULTS['EMPTY']; $value = $value ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
@ -29,6 +29,29 @@ class MapurlHelper extends MVCHelper
} }
return $form; return $form;
} // } //
public function getFieldView(string $field, array $viewDatas, array $extras = []): string
{
$value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY'];
switch ($field) {
case MapurlModel::TITLE:
$value = form_label(
$value,
'view',
[
"data-src" => current_url() . '/view/' . $viewDatas['entity']->getPK(),
"data-bs-toggle" => "modal",
"data-bs-target" => "#index_action_form",
"style" => "color: blue; cursor: pointer; font-weight:bold;",
...$extras,
]
);
break;
default:
$value = parent::getFieldView($field, $viewDatas, $extras);
break;
}
return $value;
} //
public function getRemapPage(array $viewDatas): string public function getRemapPage(array $viewDatas): string
{ {
$urls = []; $urls = [];

View File

@ -13,7 +13,7 @@ class UserHelper extends MVCHelper
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{ {
if (in_array($viewDatas['action'], ['create', 'modify'])) { if (in_array($viewDatas['action'], ['create', 'modify'])) {
$extras = (strpos($viewDatas['model']->getFieldRule($viewDatas['action'], $field), 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras]; $extras = (strpos($viewDatas['field_rules'][$field], 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras];
} }
$value = $value ?: DEFAULTS['EMPTY']; $value = $value ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
@ -64,6 +64,19 @@ class UserHelper extends MVCHelper
{ {
$value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY']; $value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
case UserModel::TITLE:
$value = form_label(
$value,
'view',
[
"data-src" => current_url() . '/view/' . $viewDatas['entity']->getPK(),
"data-bs-toggle" => "modal",
"data-bs-target" => "#index_action_form",
"style" => "color: blue; cursor: pointer; font-weight:bold;",
...$extras,
]
);
break;
case 'role': case 'role':
$roles = []; $roles = [];
foreach (explode(DEFAULTS["DELIMITER_ROLE"], $value) as $key) { foreach (explode(DEFAULTS["DELIMITER_ROLE"], $value) as $key) {

View File

@ -13,7 +13,7 @@ class UserSNSHelper extends MVCHelper
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{ {
if (in_array($viewDatas['action'], ['create', 'modify'])) { if (in_array($viewDatas['action'], ['create', 'modify'])) {
$extras = (strpos($viewDatas['model']->getFieldRule($viewDatas['action'], $field), 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras]; $extras = (strpos($viewDatas['field_rules'][$field], 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras];
} }
$value = $value ?: DEFAULTS['EMPTY']; $value = $value ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
@ -42,6 +42,29 @@ class UserSNSHelper extends MVCHelper
} }
return $form; return $form;
} // } //
public function getFieldView(string $field, array $viewDatas, array $extras = []): string
{
$value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY'];
switch ($field) {
case UserSNSModel::TITLE:
$value = form_label(
$value,
'view',
[
"data-src" => current_url() . '/view/' . $viewDatas['entity']->getPK(),
"data-bs-toggle" => "modal",
"data-bs-target" => "#index_action_form",
"style" => "color: blue; cursor: pointer; font-weight:bold;",
...$extras,
]
);
break;
default:
$value = parent::getFieldView($field, $viewDatas, $extras);
break;
}
return $value;
} //
public function getListButton(string $action, array $viewDatas, array $extras = []): string public function getListButton(string $action, array $viewDatas, array $extras = []): string
{ {
switch ($action) { switch ($action) {

View File

@ -162,11 +162,12 @@ abstract class CommonModel extends Model
throw new \Exception(__FUNCTION__ . " 변경된 내용이 없습니다."); throw new \Exception(__FUNCTION__ . " 변경된 내용이 없습니다.");
} }
// log_message("debug", var_export($entity, true)); // log_message("debug", var_export($entity, true));
//최종 저장시 오류발생하면 // 최종 저장시 오류발생하면
if (!$this->save($entity)) { if (!$this->save($entity)) {
throw new \Exception("저장오류:" . var_export($this->errors(), true)); throw new \Exception("저장오류:" . var_export($this->errors(), true));
} }
// log_message("debug", $this->getTable() . " => " . __FUNCTION__ . " DB에 {$entity->getTitle()} 저장이 완료되었습니다."); log_message("debug", $this->getTable() . " => " . __FUNCTION__ . " DB에 {$entity->getTitle()} 저장이 완료되었습니다.");
// log_message("debug", $this->getLastQuery());
return $entity; return $entity;
} catch (\Exception $e) { } catch (\Exception $e) {
$message = sprintf( $message = sprintf(

View File

@ -2,26 +2,32 @@
namespace App\Services\Cloudflare; namespace App\Services\Cloudflare;
use App\Models\Cloudflare\AccountModel;
use App\Entities\Cloudflare\AuthEntity;
use App\Entities\Cloudflare\AccountEntity; use App\Entities\Cloudflare\AccountEntity;
use App\Entities\Cloudflare\AuthEntity;
use App\Models\Cloudflare\AccountModel;
class Account extends Cloudflare class AccountService extends CloudflareService
{ {
private ?AuthEntity $_parent_entity = null; private ?AuthEntity $_parent_entity = null;
private ?AccountModel $_model = null; private ?AccountModel $_model = null;
public function __construct(AuthEntity $parent_entity) public function __construct()
{ {
$this->_parent_entity = $parent_entity; $this->class_name = "Account";
parent::__construct($parent_entity); parent::__construct();
$this->class_path .= $this->class_name;
} }
protected function getParentEntity(): AuthEntity private function getParentEntity(): AuthEntity
{ {
if ($this->_parent_entity === null) { if ($this->_parent_entity === null) {
throw new \Exception(__FUNCTION__ . "에서 부모정보가 없습니다."); throw new \Exception(__FUNCTION__ . "에서 부모정보가 없습니다.");
} }
return $this->_parent_entity; return $this->_parent_entity;
} }
private function setParentEntity(AuthEntity $parent_entity): void
{
$this->_parent_entity = $parent_entity;
$this->setAuthEntity($this->getParentEntity());
}
protected function getModel(): AccountModel protected function getModel(): AccountModel
{ {
if ($this->_model === null) { if ($this->_model === null) {
@ -29,6 +35,24 @@ class Account extends Cloudflare
} }
return $this->_model; return $this->_model;
} }
public function create(AuthEntity $parent_entity, array $formDatas): AccountEntity
{
//부모데이터정의
$this->setParentEntity($parent_entity);
return $this->getModel()->create($formDatas);
}
public function modify(AuthEntity $parent_entity, AccountEntity $entity, array $formDatas): AccountEntity
{
//부모데이터정의
$this->setParentEntity($parent_entity);
return $this->getModel()->modify($entity, $formDatas);
}
public function delete(AuthEntity $parent_entity): void
{
//부모데이터정의
$this->setParentEntity($parent_entity);
$this->getModel()->delete();
}
//Result 형태 //Result 형태
// [ // [
// {"id":"078e88a7735965b661715af13031ecb0", // {"id":"078e88a7735965b661715af13031ecb0",
@ -56,9 +80,11 @@ class Account extends Cloudflare
return $formDatas; return $formDatas;
} }
public function reload(): array public function reload(AuthEntity $parent_entity): array
{ {
log_message("notice", "\n----------Auth {$this->getAuthEntity()->getTitle()}의 Account 처리 시작-----------"); //부모데이터정의
$this->setParentEntity($parent_entity);
log_message("notice", "\n----------Auth {$this->getParentEntity()->getTitle()}의 Account 처리 시작-----------");
$entitys = []; $entitys = [];
try { try {
$results = $this->reload_procedure("accounts"); $results = $this->reload_procedure("accounts");
@ -76,7 +102,7 @@ class Account extends Cloudflare
$cnt++; $cnt++;
} }
//부모키를 기준으로 CF에 존재하지 않는 데이터 삭제용 //부모키를 기준으로 CF에 존재하지 않는 데이터 삭제용
$this->getModel()->where(AccountModel::PARENT, $this->getAuthEntity()->getPK()); $this->getModel()->where(AccountModel::PARENT, $this->getParentEntity()->getPK());
$this->getModel()->whereNotIn(AccountModel::PK, array_keys($entitys)); $this->getModel()->whereNotIn(AccountModel::PK, array_keys($entitys));
$this->getModel()->delete(); $this->getModel()->delete();
// log_message("debug", $this->getModel()->getLastQuery()); // log_message("debug", $this->getModel()->getLastQuery());
@ -85,7 +111,7 @@ class Account extends Cloudflare
log_message("error", $e->getMessage()); log_message("error", $e->getMessage());
throw new \Exception($e->getMessage()); throw new \Exception($e->getMessage());
} }
log_message("notice", message: "\n-----------Auth {$this->getAuthEntity()->getTitle()}의 Account 처리[" . count($entitys) . "개] 완료-----------"); log_message("notice", message: "\n-----------Auth {$this->getParentEntity()->getTitle()}의 Account 처리[" . count($entitys) . "개] 완료-----------");
return $entitys; return $entitys;
} }
} }

View File

@ -0,0 +1,36 @@
<?php
namespace App\Services\Cloudflare;
use App\Entities\Cloudflare\AuthEntity;
use App\Models\Cloudflare\AuthModel;
class AuthService extends CloudflareService
{
private ?AuthModel $_model = null;
public function __construct()
{
$this->class_name = "Auth";
parent::__construct();
$this->class_path .= $this->class_name;
}
protected function getModel(): AuthModel
{
if ($this->_model === null) {
$this->_model = new AuthModel();
}
return $this->_model;
}
public function create(array $formDatas): AuthEntity
{
return $this->getModel()->create($formDatas);
}
public function modify(AuthEntity $entity, array $formDatas): AuthEntity
{
return $this->getModel()->modify($entity, $formDatas);
}
public function delete(): void
{
$this->getModel()->delete();
}
}

View File

@ -2,28 +2,28 @@
namespace App\Services\Cloudflare; namespace App\Services\Cloudflare;
use App\Models\Cloudflare\AuthModel;
use App\Libraries\MySocket\CloudflareSocket;
use App\Entities\Cloudflare\AuthEntity; use App\Entities\Cloudflare\AuthEntity;
use App\Libraries\MySocket\CloudflareSocket;
use App\Models\Cloudflare\AuthModel;
use App\Services\CommonService;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
abstract class Cloudflare abstract class CloudflareService extends CommonService
{ {
private $_mySocket = null; private $_mySockets = [];
private $_auth_entity = null; private $_auth_entity = null;
private $_authModel = null; private $_authModel = null;
protected function __construct(AuthEntity $auth_entity) protected function __construct()
{ {
$this->_auth_entity = $auth_entity; parent::__construct();
$this->class_path = "Cloudflare/";
} }
abstract protected function getArrayByResult(\stdClass $result, array $formDatas = []): array;
abstract protected function getParentEntity(): mixed;
final public function getMySocket(): CloudflareSocket final public function getMySocket(): CloudflareSocket
{ {
if ($this->_mySocket === null) { if (!isset($this->_mySockets[$this->getAuthEntity()->getPK()])) {
$this->_mySocket = new CloudflareSocket($this->getAuthEntity()); $this->_mySockets[$this->getAuthEntity()->getPK()] = new CloudflareSocket($this->getAuthEntity());
} }
return $this->_mySocket; return $this->_mySockets[$this->getAuthEntity()->getPK()];
} }
final protected function getAuthEntity(): AuthEntity final protected function getAuthEntity(): AuthEntity
{ {
@ -32,6 +32,10 @@ abstract class Cloudflare
} }
return $this->_auth_entity; return $this->_auth_entity;
} }
final protected function setAuthEntity(AuthEntity $auth_entity): void
{
$this->_auth_entity = $auth_entity;
}
final protected function getAuthModel(): AuthModel final protected function getAuthModel(): AuthModel
{ {
if ($this->_authModel === null) { if ($this->_authModel === null) {

View File

@ -7,14 +7,27 @@ use App\Entities\Cloudflare\ZoneEntity;
use App\Models\Cloudflare\AccountModel; use App\Models\Cloudflare\AccountModel;
use App\Models\Cloudflare\FirewallModel; use App\Models\Cloudflare\FirewallModel;
class Firewall extends Cloudflare class FirewallService extends CloudflareService
{ {
private ?ZoneEntity $_parent_entity = null; private ?ZoneEntity $_parent_entity = null;
private ?FirewallModel $_model = null; private ?FirewallModel $_model = null;
private ?AccountModel $_accountModel = null; private ?AccountModel $_accountModel = null;
public function __construct(ZoneEntity $zone_entity) public function __construct()
{ {
$this->_parent_entity = $zone_entity; $this->class_name = "Firewall";
parent::__construct();
$this->class_path .= $this->class_name;
}
private function getParentEntity(): ZoneEntity
{
if ($this->_parent_entity === null) {
throw new \Exception(__FUNCTION__ . "에서 부모정보가 없습니다.");
}
return $this->_parent_entity;
}
private function setParentEntity(mixed $parent_entity): void
{
$this->_parent_entity = $parent_entity;
$account_entity = $this->getAccountModel()->getEntityByPK($this->getParentEntity()->getParent()); $account_entity = $this->getAccountModel()->getEntityByPK($this->getParentEntity()->getParent());
if ($account_entity === null) { if ($account_entity === null) {
throw new \Exception("해당 계정정보를 찾을수 없습니다."); throw new \Exception("해당 계정정보를 찾을수 없습니다.");
@ -23,14 +36,7 @@ class Firewall extends Cloudflare
if ($auth_entity === null) { if ($auth_entity === null) {
throw new \Exception("해당 계정정보를 찾을수 없습니다."); throw new \Exception("해당 계정정보를 찾을수 없습니다.");
} }
parent::__construct($auth_entity); $this->setAuthEntity($auth_entity);
}
protected function getParentEntity(): ZoneEntity
{
if ($this->_parent_entity === null) {
throw new \Exception(__FUNCTION__ . "에서 부모정보가 없습니다.");
}
return $this->_parent_entity;
} }
protected function getModel(): FirewallModel protected function getModel(): FirewallModel
{ {
@ -60,8 +66,10 @@ class Firewall extends Cloudflare
// log_message("debug", print_r($formDatas, true)); // log_message("debug", print_r($formDatas, true));
return $formDatas; return $formDatas;
} }
public function modify(FirewallEntity $entity, array $formDatas): FirewallEntity public function modify(ZoneEntity $parent_entity, FirewallEntity $entity, array $formDatas): FirewallEntity
{ {
//부모데이터정의
$this->setParentEntity($parent_entity);
$datas = [ $datas = [
'id' => $entity->getPK(), // 수정할 rule의 ID 'id' => $entity->getPK(), // 수정할 rule의 ID
"action" => $entity->mode, "action" => $entity->mode,
@ -83,8 +91,10 @@ class Firewall extends Cloudflare
return $entity; return $entity;
} }
//Reload //Reload
public function reload(): array public function reload(ZoneEntity $parent_entity): array
{ {
//부모데이터정의
$this->setParentEntity($parent_entity);
// log_message("notice", "\n-----------Zone {$this->getParentEntity()->getTitle()}의 Firewall 처리 시작-----------"); // log_message("notice", "\n-----------Zone {$this->getParentEntity()->getTitle()}의 Firewall 처리 시작-----------");
$entitys = []; $entitys = [];
try { try {

View File

@ -7,14 +7,27 @@ use App\Entities\Cloudflare\ZoneEntity;
use App\Models\Cloudflare\AccountModel; use App\Models\Cloudflare\AccountModel;
use App\Models\Cloudflare\RecordModel; use App\Models\Cloudflare\RecordModel;
class Record extends Cloudflare class RecordService extends CloudflareService
{ {
private ?ZoneEntity $_parent_entity = null; private ?ZoneEntity $_parent_entity = null;
private ?RecordModel $_model = null; private ?RecordModel $_model = null;
private ?AccountModel $_accountModel = null; private ?AccountModel $_accountModel = null;
public function __construct(ZoneEntity $zone_entity) public function __construct()
{ {
$this->_parent_entity = $zone_entity; $this->class_name = "Record";
parent::__construct();
$this->class_path .= $this->class_name;
}
private function getParentEntity(): ZoneEntity
{
if ($this->_parent_entity === null) {
throw new \Exception(__FUNCTION__ . "에서 부모정보가 없습니다.");
}
return $this->_parent_entity;
}
private function setParentEntity(mixed $parent_entity): void
{
$this->_parent_entity = $parent_entity;
$account_entity = $this->getAccountModel()->getEntityByPK($this->getParentEntity()->getParent()); $account_entity = $this->getAccountModel()->getEntityByPK($this->getParentEntity()->getParent());
if ($account_entity === null) { if ($account_entity === null) {
throw new \Exception("해당 계정정보를 찾을수 없습니다."); throw new \Exception("해당 계정정보를 찾을수 없습니다.");
@ -23,14 +36,7 @@ class Record extends Cloudflare
if ($auth_entity === null) { if ($auth_entity === null) {
throw new \Exception("해당 계정정보를 찾을수 없습니다."); throw new \Exception("해당 계정정보를 찾을수 없습니다.");
} }
parent::__construct($auth_entity); $this->setAuthEntity($auth_entity);
}
protected function getParentEntity(): ZoneEntity
{
if ($this->_parent_entity === null) {
throw new \Exception(__FUNCTION__ . "에서 부모정보가 없습니다.");
}
return $this->_parent_entity;
} }
protected function getModel(): RecordModel protected function getModel(): RecordModel
{ {
@ -63,8 +69,10 @@ class Record extends Cloudflare
// log_message("debug", print_r($formDatas, true)); // log_message("debug", print_r($formDatas, true));
return $formDatas; return $formDatas;
} }
public function create(string $host, string $type, string $content, string $proxied): RecordEntity public function create(ZoneEntity $parent_entity, string $host, string $type, string $content, string $proxied): RecordEntity
{ {
//부모데이터정의
$this->setParentEntity($parent_entity);
//Socket용 //Socket용
//호스트생성을 위해 Cloudflare에 전송 //호스트생성을 위해 Cloudflare에 전송
$datas = [ $datas = [
@ -78,8 +86,10 @@ class Record extends Cloudflare
//DB생성 //DB생성
return $this->getModel()->create($this->getArrayByResult($body->result)); return $this->getModel()->create($this->getArrayByResult($body->result));
} }
public function modify(RecordEntity $entity, array $formDatas): RecordEntity public function modify(ZoneEntity $parent_entity, RecordEntity $entity, array $formDatas): RecordEntity
{ {
//부모데이터정의
$this->setParentEntity($parent_entity);
//TTL값은 CDN(proxied)가 사용함일때는 무조건 1, 않함일때는 120이 적용 //TTL값은 CDN(proxied)가 사용함일때는 무조건 1, 않함일때는 120이 적용
$datas = [ $datas = [
'type' => isset($formDatas['type']) ? $formDatas['type'] : $entity->type, 'type' => isset($formDatas['type']) ? $formDatas['type'] : $entity->type,
@ -104,16 +114,20 @@ class Record extends Cloudflare
// DB 수정 // DB 수정
return $this->getModel()->modify($entity, $this->getArrayByResult($body->result)); return $this->getModel()->modify($entity, $this->getArrayByResult($body->result));
} }
public function delete(RecordEntity $entity): RecordEntity public function delete(ZoneEntity $parent_entity, RecordEntity $entity): RecordEntity
{ {
//부모데이터정의
$this->setParentEntity($parent_entity);
$this->getMySocket()->delete("zones/{$this->getParentEntity()->getPK()}/dns_records/{$entity->getPK()}"); $this->getMySocket()->delete("zones/{$this->getParentEntity()->getPK()}/dns_records/{$entity->getPK()}");
//DB삭제 //DB삭제
$this->getModel()->delete($entity->getPK()); $this->getModel()->delete($entity->getPK());
log_message("debug", $this->getModel()->getLastQuery()); log_message("debug", $this->getModel()->getLastQuery());
return $entity; return $entity;
} }
public function sync(RecordEntity $entity): RecordEntity public function sync(ZoneEntity $parent_entity, RecordEntity $entity): RecordEntity
{ {
//부모데이터정의
$this->setParentEntity($parent_entity);
// 기존 Sync형태 // 기존 Sync형태
$response = $this->getMySocket()->get("zones/{$this->getParentEntity()->getPK()}/dns_records/{$entity->getPK()}"); $response = $this->getMySocket()->get("zones/{$this->getParentEntity()->getPK()}/dns_records/{$entity->getPK()}");
$body = json_decode($response->getBody()); $body = json_decode($response->getBody());
@ -138,8 +152,10 @@ class Record extends Cloudflare
return $entity; return $entity;
} }
//Reload //Reload
public function reload(): array public function reload(ZoneEntity $parent_entity): array
{ {
//부모데이터정의
$this->setParentEntity($parent_entity);
// log_message("notice", "\n-----------Zone {$this->getParentEntity()->getTitle()}의 Record 처리 시작-----------"); // log_message("notice", "\n-----------Zone {$this->getParentEntity()->getTitle()}의 Record 처리 시작-----------");
$entitys = []; $entitys = [];
try { try {

View File

@ -6,7 +6,7 @@ use App\Entities\Cloudflare\AccountEntity;
use App\Entities\Cloudflare\ZoneEntity; use App\Entities\Cloudflare\ZoneEntity;
use App\Models\Cloudflare\ZoneModel; use App\Models\Cloudflare\ZoneModel;
class Zone extends Cloudflare class ZoneService extends CloudflareService
{ {
private ?AccountEntity $_parent_entity = null; private ?AccountEntity $_parent_entity = null;
private ?ZoneModel $_model = null; private ?ZoneModel $_model = null;
@ -17,22 +17,28 @@ class Zone extends Cloudflare
'ssl' => 'flexible', 'ssl' => 'flexible',
'always_use_https' => 'off' 'always_use_https' => 'off'
]; ];
public function __construct(AccountEntity $account_entity) public function __construct()
{ {
$this->_parent_entity = $account_entity; $this->class_name = "Zone";
$auth_entity = $this->getAuthModel()->getEntityByPK(uid: $this->getParentEntity()->getParent()); parent::__construct();
if ($auth_entity === null) { $this->class_path .= $this->class_name;
throw new \Exception("해당 계정정보를 찾을수 없습니다.");
}
parent::__construct($auth_entity);
} }
protected function getParentEntity(): AccountEntity private function getParentEntity(): AccountEntity
{ {
if ($this->_parent_entity === null) { if ($this->_parent_entity === null) {
throw new \Exception(__FUNCTION__ . "에서 부모정보가 없습니다."); throw new \Exception(__FUNCTION__ . "에서 부모정보가 없습니다.");
} }
return $this->_parent_entity; return $this->_parent_entity;
} }
private function setParentEntity(mixed $parent_entity): void
{
$this->_parent_entity = $parent_entity;
$auth_entity = $this->getAuthModel()->getEntityByPK(uid: $this->getParentEntity()->getParent());
if ($auth_entity === null) {
throw new \Exception("해당 계정정보를 찾을수 없습니다.");
}
$this->setAuthEntity($auth_entity);
}
protected function getModel(): ZoneModel protected function getModel(): ZoneModel
{ {
if ($this->_model === null) { if ($this->_model === null) {
@ -94,8 +100,10 @@ class Zone extends Cloudflare
//최종 결과값은 body->result->id='필드명',body->result->value='on/off'이런식으로 받음 //최종 결과값은 body->result->id='필드명',body->result->value='on/off'이런식으로 받음
return $body->result->value; return $body->result->value;
} }
public function create(string $domain, bool $jump_start = false): ZoneEntity public function create(AccountEntity $parent_entity, string $domain, bool $jump_start = false): ZoneEntity
{ {
//부모데이터정의
$this->setParentEntity($parent_entity);
//Socket용 //Socket용
//도메인생성을 위해 Cloudflare에 전송 //도메인생성을 위해 Cloudflare에 전송
$datas = [ $datas = [
@ -113,8 +121,10 @@ class Zone extends Cloudflare
} }
return $this->getModel()->create($formDatas); return $this->getModel()->create($formDatas);
} }
public function modify(ZoneEntity $entity, array $formDatas): ZoneEntity public function modify(AccountEntity $parent_entity, ZoneEntity $entity, array $formDatas): ZoneEntity
{ {
//부모데이터정의
$this->setParentEntity($parent_entity);
// throw new \Exception("zone:modify" . var_export($formDatas, true)); // throw new \Exception("zone:modify" . var_export($formDatas, true));
foreach ($formDatas as $field => $value) { foreach ($formDatas as $field => $value) {
//modify,toggle,batchjob 사용 셋팅 ipv6 , //development_mode , //security_level //modify,toggle,batchjob 사용 셋팅 ipv6 , //development_mode , //security_level
@ -123,16 +133,19 @@ class Zone extends Cloudflare
//DB수정 //DB수정
return $this->getModel()->modify($entity, $formDatas); return $this->getModel()->modify($entity, $formDatas);
} }
public function delete(ZoneEntity $entity): ZoneEntity public function delete(AccountEntity $parent_entity, ZoneEntity $entity): ZoneEntity
{ {
//부모데이터정의
$this->setParentEntity($parent_entity);
$this->getMySocket()->delete("zones/{$entity->getPK()}"); $this->getMySocket()->delete("zones/{$entity->getPK()}");
//DB삭제 //DB삭제
$this->getModel()->delete($entity->getPK()); $this->getModel()->delete($entity->getPK());
log_message("debug", $this->getModel()->getLastQuery()); log_message("debug", $this->getModel()->getLastQuery());
return $entity; return $entity;
} }
public function sync(ZoneEntity $entity): ZoneEntity public function sync(AccountEntity $parent_entity, ZoneEntity $entity): ZoneEntity
{ {
$this->setParentEntity($parent_entity);
$response = $this->getMySocket()->get("zones/{$entity->getPK()}"); $response = $this->getMySocket()->get("zones/{$entity->getPK()}");
$body = json_decode($response->getBody()); $body = json_decode($response->getBody());
$formDatas = $this->getArrayByResult($body->result); $formDatas = $this->getArrayByResult($body->result);
@ -144,8 +157,10 @@ class Zone extends Cloudflare
return $entity; return $entity;
} }
//Reload //Reload
public function reload(): array public function reload(AccountEntity $parent_entity): array
{ {
//부모데이터정의
$this->setParentEntity($parent_entity);
log_message("notice", "\n-----------Account {$this->getParentEntity()->getTitle()}의 Zone처리 시작-----------"); log_message("notice", "\n-----------Account {$this->getParentEntity()->getTitle()}의 Zone처리 시작-----------");
$entitys = []; $entitys = [];
try { try {

View File

@ -1,10 +0,0 @@
<?php
namespace App\Services;
abstract class Common
{
public function __construct()
{
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Services;
abstract class CommonService
{
private $_serviceDatas = [];
public function __construct() {}
abstract protected function getModel(): mixed;
final public function __get($name)
{
if (!array_key_exists($name, $this->_serviceDatas)) {
return null;
}
return $this->_serviceDatas[$name];
}
final public function __set($name, $value): void
{
$this->_serviceDatas[$name] = $value;
}
final public function getServiceDatas(): array
{
return $this->_serviceDatas;
}
}

View File

@ -0,0 +1,37 @@
<?php
namespace App\Services;
use App\Models\MapurlModel;
use App\Entities\MapurlEntity;
class MapurlService extends CommonService
{
private $_view_path = "";
private ?MapurlModel $_model = null;
public function __construct()
{
$this->class_name = "Mapurl";
parent::__construct();
$this->class_path .= $this->class_name;
}
protected function getModel(): MapurlModel
{
if ($this->_model === null) {
$this->_model = new MapurlModel();
}
return $this->_model;
}
public function create(array $formDatas): MapurlEntity
{
return $this->getModel()->create($formDatas);
}
public function modify(MapurlEntity $entity, array $formDatas): MapurlEntity
{
return $this->getModel()->modify($entity, $formDatas);
}
public function delete(): void
{
$this->getModel()->delete();
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace App\Services;
use App\Models\UserSNSModel;
use App\Entities\UserSNSEntity;
class UserSNSService extends CommonService
{
private ?UserSNSModel $_model = null;
public function __construct()
{
$this->class_name = "UserSNS";
parent::__construct();
$this->class_path .= $this->class_name;
}
protected function getModel(): UserSNSModel
{
if ($this->_model === null) {
$this->_model = new UserSNSModel();
}
return $this->_model;
}
public function create(array $formDatas): UserSNSEntity
{
return $this->getModel()->create($formDatas);
}
public function modify(UserSNSEntity $entity, array $formDatas): UserSNSEntity
{
return $this->getModel()->modify($entity, $formDatas);
}
public function delete(): void
{
$this->getModel()->delete();
}
}

View File

@ -5,29 +5,22 @@ namespace App\Services;
use App\Models\UserModel; use App\Models\UserModel;
use App\Entities\UserEntity; use App\Entities\UserEntity;
class User extends Common class UserService extends CommonService
{ {
private ?UserModel $_model = null; private ?UserModel $_model = null;
public function __construct() public function __construct()
{ {
$this->class_name = "User";
parent::__construct(); parent::__construct();
$this->class_path .= $this->class_name;
} }
public function getModel(): UserModel protected function getModel(): UserModel
{ {
if ($this->_model === null) { if ($this->_model === null) {
$this->_model = new UserModel(); $this->_model = new UserModel();
} }
return $this->_model; return $this->_model;
} }
public function find(array $wheres): ?UserEntity
{
return $this->getModel()->where($wheres)->first();
}
public function findAll(array $wheres = []): array
{
return $this->getModel()->where($wheres)->findAll();
}
public function create(array $formDatas): UserEntity public function create(array $formDatas): UserEntity
{ {
return $this->getModel()->create($formDatas); return $this->getModel()->create($formDatas);
@ -36,8 +29,8 @@ class User extends Common
{ {
return $this->getModel()->modify($entity, $formDatas); return $this->getModel()->modify($entity, $formDatas);
} }
public function delete(array $wheres): void public function delete(): void
{ {
$this->getModel()->where($wheres)->delete(); $this->getModel()->delete();
} }
} }