daemon-idc init

This commit is contained in:
최준흠 2026-03-04 11:38:35 +09:00
parent a24c0ceb3e
commit a0d9780189
3 changed files with 45 additions and 44 deletions

View File

@ -10,7 +10,7 @@ use Psr\Log\LoggerInterface;
abstract class AjaxController extends AbstractCRUDController abstract class AjaxController extends AbstractCRUDController
{ {
private $_layout = 'front'; private $_layout = "front";
protected $layouts = []; protected $layouts = [];
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{ {
@ -21,23 +21,23 @@ abstract class AjaxController extends AbstractCRUDController
protected function action_init_process(string $action, array $formDatas = []): void protected function action_init_process(string $action, array $formDatas = []): void
{ {
parent::action_init_process($action, $formDatas); parent::action_init_process($action, $formDatas);
$this->addViewDatas('layout', $this->layouts); $this->addViewDatas("layout", $this->layouts);
$this->addViewDatas('title', $this->getTitle()); $this->addViewDatas("title", $this->getTitle());
$this->addViewDatas('helper', $this->service->getHelper()); $this->addViewDatas("helper", $this->service->getHelper());
$this->service->getActionForm()->form_init_process($action, $formDatas); $this->service->getActionForm()->form_init_process($action, $formDatas);
$this->addViewDatas('formFields', $this->service->getActionForm()->getFormFields()); $this->addViewDatas("formFields", $this->service->getActionForm()->getFormFields());
$this->addViewDatas('formRules', $this->service->getActionForm()->getFormRules()); $this->addViewDatas("formRules", $this->service->getActionForm()->getFormRules());
$this->addViewDatas('formFilters', $this->service->getActionForm()->getFormFilters()); $this->addViewDatas("formFilters", $this->service->getActionForm()->getFormFilters());
$this->addViewDatas('formOptions', $this->service->getActionForm()->getFormOptions()); $this->addViewDatas("formOptions", $this->service->getActionForm()->getFormOptions());
$this->addViewDatas('index_actionButtons', $this->service->getActionForm()->getActionButtons()); $this->addViewDatas("index_actionButtons", $this->service->getActionForm()->getActionButtons());
$this->addViewDatas('index_batchjobFields', $this->service->getActionForm()->getBatchjobFilters()); $this->addViewDatas("index_batchjobFields", $this->service->getActionForm()->getBatchjobFilters());
$this->addViewDatas('index_batchjobButtons', $this->service->getActionForm()->getBatchjobButtons()); $this->addViewDatas("index_batchjobButtons", $this->service->getActionForm()->getBatchjobButtons());
} }
protected function ok(array $data = [], int $status = 200): ResponseInterface protected function ok(array $data = [], int $status = 200): ResponseInterface
{ {
return $this->response->setStatusCode($status)->setJSON([ return $this->response->setStatusCode($status)->setJSON([
'ok' => true, "ok" => true,
...$data, ...$data,
]); ]);
} }
@ -45,8 +45,8 @@ abstract class AjaxController extends AbstractCRUDController
protected function fail(string $message, int $status = 400, array $extra = []): ResponseInterface protected function fail(string $message, int $status = 400, array $extra = []): ResponseInterface
{ {
return $this->response->setStatusCode($status)->setJSON([ return $this->response->setStatusCode($status)->setJSON([
'ok' => false, "ok" => false,
'message' => $message, "message" => $message,
...$extra, ...$extra,
]); ]);
} }
@ -55,7 +55,7 @@ abstract class AjaxController extends AbstractCRUDController
{ {
// fetch + X-Requested-With 로 들어오는 경우 // fetch + X-Requested-With 로 들어오는 경우
if (!$this->request->isAJAX()) { if (!$this->request->isAJAX()) {
return $this->fail('Invalid request', 400); return $this->fail("Invalid request", 400);
} }
return null; return null;
} }
@ -65,55 +65,55 @@ abstract class AjaxController extends AbstractCRUDController
if ($e instanceof FormValidationException) { if ($e instanceof FormValidationException) {
// ✅ 필드별 + 전역 메시지 // ✅ 필드별 + 전역 메시지
return $this->fail( return $this->fail(
$e->getMessage() ?: '입력값을 확인해 주세요.', $e->getMessage() ?: "입력값을 확인해 주세요.",
422, 422,
['errors' => $e->getErrors()] ["errors" => $e->getErrors()]
); );
} }
log_message('error', '[AJAX] ' . $e->getMessage()); log_message("error", "[AJAX] " . $e->getMessage());
return $this->fail('처리 중 오류가 발생했습니다.', 500); return $this->fail("처리 중 오류가 발생했습니다.", 500);
} }
public function create(): ResponseInterface public function create(): ResponseInterface
{ {
if (!$this->request->isAJAX()) { if (!$this->request->isAJAX()) {
return $this->response->setStatusCode(400)->setJSON([ return $this->response->setStatusCode(400)->setJSON([
'ok' => false, "ok" => false,
'message' => static::class . '->' . __FUNCTION__ . "에서 오류발생: AJAX요청 형식이 아닙니다." "message" => static::class . "->" . __FUNCTION__ . "에서 오류발생: AJAX요청 형식이 아닙니다."
]); ]);
} }
try { try {
$formDatas = $this->request->getPost(); $formDatas = $this->request->getPost();
// log_message('error', 'POST=' . json_encode($formDatas, JSON_UNESCAPED_UNICODE)); // log_message("error", "POST=" . json_encode($formDatas, JSON_UNESCAPED_UNICODE));
$entity = $this->service->create($formDatas); $entity = $this->service->create($formDatas);
return $this->response->setStatusCode(201)->setJSON([ return $this->response->setStatusCode(201)->setJSON([
'ok' => true, "ok" => true,
'message' => '문의가 접수되었습니다.', "message" => "문의가 접수되었습니다.",
'data' => ['pk' => $entity->getPK()], "data" => ["pk" => $entity->getPK()],
]); ]);
} catch (FormValidationException $e) { } catch (FormValidationException $e) {
// log_message('error', 'CAUGHT FormValidationException: ' . print_r($e->getErrors(), true)); // log_message("error", "CAUGHT FormValidationException: " . print_r($e->getErrors(), true));
return $this->response->setStatusCode(422)->setJSON([
'ok' => false,
'message' => '입력값을 확인해 주세요.',
'errors' => $e->getErrors(),
]);
} catch (\Throwable $e) {
// ✅ 혹시 서비스에서 예외를 감싸버린 경우에도 에러를 최대한 복구 // ✅ 혹시 서비스에서 예외를 감싸버린 경우에도 에러를 최대한 복구
$errors = service('validation')->getErrors(); $errors = service("validation")->getErrors();
if (!empty($errors)) { if (!empty($errors)) {
log_message('error', 'FALLBACK validation errors: ' . print_r($errors, true)); log_message("error", "FALLBACK validation errors: " . print_r($errors, true));
return $this->response->setStatusCode(422)->setJSON([ return $this->response->setStatusCode(422)->setJSON([
'ok' => false, "ok" => false,
'message' => '입력값을 확인해 주세요.', "message" => "입력값을 확인해 주세요.",
'errors' => $errors, "errors" => $errors,
]); ]);
} }
return $this->response->setStatusCode(422)->setJSON([
"ok" => false,
"message" => "입력값을 확인해 주세요.",
"errors" => $e->getErrors(),
]);
} catch (\Throwable $e) {
return $this->response->setStatusCode(500)->setJSON([ return $this->response->setStatusCode(500)->setJSON([
'ok' => false, "ok" => false,
'message' => '처리 중 오류가 발생했습니다.', "message" => "처리 중 오류가 발생했습니다.\n" . $e->getMessage(),
]); ]);
} }
} }

View File

@ -12,6 +12,7 @@ use Psr\Log\LoggerInterface;
abstract class AuthController extends AbstractWebController abstract class AuthController extends AbstractWebController
{ {
private $_layout = 'auth'; private $_layout = 'auth';
protected $layouts = [];
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);

View File

@ -38,27 +38,27 @@ class AuthContext
// Public Accessors (AuthService에서 이동) // Public Accessors (AuthService에서 이동)
// ---------------------------------------------------- // ----------------------------------------------------
public function getUID(): int public function getUID(): int|null
{ {
return $this->getAuthInfo('uid'); return $this->getAuthInfo('uid');
} }
public function getID(): string public function getID(): string|null
{ {
return $this->getAuthInfo('id'); return $this->getAuthInfo('id');
} }
public function getName(): string public function getName(): string|null
{ {
return $this->getAuthInfo('name'); return $this->getAuthInfo('name');
} }
public function getRole(): string public function getRole(): string|null
{ {
return $this->getAuthInfo('role'); return $this->getAuthInfo('role');
} }
public function getRoles(): array public function getRoles(): array|null
{ {
return explode(DEFAULTS['DELIMITER_COMMA'], $this->getRole()); return explode(DEFAULTS['DELIMITER_COMMA'], $this->getRole());
} }