dbmsv4 init...5

This commit is contained in:
최준흠 2026-02-03 15:06:47 +09:00
parent fe8b45db35
commit 777ea0f2ff
4 changed files with 27 additions and 14 deletions

View File

@ -18,9 +18,9 @@ class ServerEntity extends EquipmentEntity
'code' => '', 'code' => '',
'title' => '', 'title' => '',
'type' => '', 'type' => '',
'ip' => '', 'ip' => null,
'viewer' => '', 'viewer' => null,
'os' => '', 'os' => null,
'price' => 0, 'price' => 0,
'manufactur_at' => '', 'manufactur_at' => '',
'format_at' => '', 'format_at' => '',

View File

@ -250,6 +250,12 @@ abstract class CommonService
} }
} }
//Action 작업시 field에따른 Hook처리(각 Service에서 override);
protected function action_process_fieldhook(string $field, $value, array $formDatas): array
{
return $formDatas;
}
//생성용 //생성용
protected function create_process(array $formDatas): CommonEntity protected function create_process(array $formDatas): CommonEntity
{ {
@ -257,11 +263,13 @@ abstract class CommonService
$actionForm = $this->getActionForm(); $actionForm = $this->getActionForm();
if ($actionForm instanceof CommonForm) { if ($actionForm instanceof CommonForm) {
$actionForm->action_init_process('create', $formDatas); $actionForm->action_init_process('create', $formDatas);
foreach ($formDatas as $field => $value) {
$formDatas = $this->action_process_fieldhook($field, $value, $formDatas);
}
$actionForm->validate($formDatas); $actionForm->validate($formDatas);
} }
$entityClass = $this->getEntityClass(); $entityClass = $this->getEntityClass();
$entity = new $entityClass($formDatas); $entity = new $entityClass($formDatas);
// dd($entity);
if (!$entity instanceof $entityClass) { if (!$entity instanceof $entityClass) {
throw new RuntimeException("Return Type은 {$entityClass}만 가능"); throw new RuntimeException("Return Type은 {$entityClass}만 가능");
} }
@ -280,10 +288,6 @@ abstract class CommonService
} }
//수정용 //수정용
protected function modify_process_fieldhook(string $field, $value, array $formDatas): array
{
return $formDatas;
}
protected function modify_process($entity, array $formDatas): CommonEntity protected function modify_process($entity, array $formDatas): CommonEntity
{ {
try { try {
@ -291,7 +295,7 @@ abstract class CommonService
if ($actionForm instanceof CommonForm) { if ($actionForm instanceof CommonForm) {
$actionForm->action_init_process('modify', $formDatas); $actionForm->action_init_process('modify', $formDatas);
foreach ($formDatas as $field => $value) { foreach ($formDatas as $field => $value) {
$formDatas = $this->modify_process_fieldhook($field, $value, $formDatas); $formDatas = $this->action_process_fieldhook($field, $value, $formDatas);
} }
$actionForm->validate($formDatas); // ✅ 여기서 검증 $actionForm->validate($formDatas); // ✅ 여기서 검증
} }

View File

@ -47,7 +47,7 @@ class ClientService extends CustomerService
parent::setOrderBy($field, $value); parent::setOrderBy($field, $value);
} }
protected function modify_process_fieldhook(string $field, $value, array $formDatas): array protected function action_process_fieldhook(string $field, $value, array $formDatas): array
{ {
switch ($field) { switch ($field) {
case 'role': case 'role':
@ -56,17 +56,17 @@ class ClientService extends CustomerService
} elseif (!is_array($value)) { } elseif (!is_array($value)) {
$value = []; $value = [];
} }
$value = array_values(array_filter(array_map( $value = array_values(array_filter(array_map(
fn($v) => trim((string) ($v ?? ''), " \t\n\r\0\x0B\""), fn($v) => trim((string) ($v ?? ''), " \t\n\r\0\x0B\""),
$value $value
))); )));
$formDatas[$field] = $value; $formDatas[$field] = $value;
break; break;
case "format_at":
$formDatas[$field] = $value === '' ? null : $value;
break;
default: default:
$formDatas = parent::modify_process_fieldhook($field, $value, $formDatas); $formDatas = parent::action_process_fieldhook($field, $value, $formDatas);
break; break;
} }
return $formDatas; return $formDatas;

View File

@ -123,6 +123,9 @@ class ServiceService extends CustomerService
} }
protected function create_process(array $formDatas): ServiceEntity protected function create_process(array $formDatas): ServiceEntity
{ {
if (empty($formDatas['site'])) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 사이트가 지정되지 않았습니다.");
}
if (empty($formDatas['serverinfo_uid'])) { if (empty($formDatas['serverinfo_uid'])) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 서버가 지정되지 않았습니다."); throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 서버가 지정되지 않았습니다.");
} }
@ -144,6 +147,12 @@ class ServiceService extends CustomerService
} }
protected function modify_process($entity, array $formDatas): ServiceEntity protected function modify_process($entity, array $formDatas): ServiceEntity
{ {
if (empty($formDatas['site'])) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 사이트가 지정되지 않았습니다.");
}
if (empty($formDatas['serverinfo_uid'])) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 서버가 지정되지 않았습니다.");
}
//변경전 정보 //변경전 정보
$oldEntity = clone $entity; $oldEntity = clone $entity;
//수정폼에는 없는 필수항목 지정용(code) //수정폼에는 없는 필수항목 지정용(code)