diff --git a/app/Controllers/AbstractCRUDController.php b/app/Controllers/AbstractCRUDController.php
index 26ed81b..d756dab 100644
--- a/app/Controllers/AbstractCRUDController.php
+++ b/app/Controllers/AbstractCRUDController.php
@@ -15,10 +15,7 @@ abstract class AbstractCRUDController extends AbstractWebController
{
// ๐ก ํต์ฌ 1: ๊ฐ ์์ ํด๋์ค๊ฐ ์ฌ์ฉํ Entity ํด๋์ค ๊ฒฝ๋ก๋ฅผ ๋ฐํํ๋๋ก ๊ฐ์
// ์ด ๋ฉ์๋๋ ์์ ํด๋์ค์์ ๋ฐ๋์ ๊ตฌํ๋์ด์ผ ํฉ๋๋ค.
- abstract protected function getEntityClass(): string;
-
// --- ์์ฑ (Create) ---
-
protected function create_form_process(array $formDatas = []): array
{
//์ด๊ธฐ ๊ธฐ๋ณธ Default๊ฐ ์ง์
@@ -64,7 +61,7 @@ abstract class AbstractCRUDController extends AbstractWebController
$this->action_init_process($action);
$entity = $this->create_process();
// ๐ก ๋์ ์ผ๋ก ๊ฐ์ ธ์จ Entity ํด๋์ค ์ด๋ฆ์ผ๋ก instanceof ๊ฒ์ฌ
- $entityClass = $this->getEntityClass();
+ $entityClass = $this->service->getEntityClass();
if (!$entity instanceof $entityClass) {
throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ {$entityClass}๋ง ๊ฐ๋ฅ");
}
@@ -97,7 +94,7 @@ abstract class AbstractCRUDController extends AbstractWebController
try {
$entity = $this->modify_form_process($uid);
// ๐ก ๋์ ์ผ๋ก ๊ฐ์ ธ์จ Entity ํด๋์ค ์ด๋ฆ์ผ๋ก instanceof ๊ฒ์ฌ
- $entityClass = $this->getEntityClass();
+ $entityClass = $this->service->getEntityClass();
if (!$entity instanceof $entityClass) {
throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ {$entityClass}๋ง ๊ฐ๋ฅ");
}
@@ -131,7 +128,7 @@ abstract class AbstractCRUDController extends AbstractWebController
$this->action_init_process($action);
$entity = $this->modify_process($uid);
// ๐ก ๋์ ์ผ๋ก ๊ฐ์ ธ์จ Entity ํด๋์ค ์ด๋ฆ์ผ๋ก instanceof ๊ฒ์ฌ
- $entityClass = $this->getEntityClass();
+ $entityClass = $this->service->getEntityClass();
if (!$entity instanceof $entityClass) {
throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ {$entityClass}๋ง ๊ฐ๋ฅ");
}
@@ -158,7 +155,7 @@ abstract class AbstractCRUDController extends AbstractWebController
try {
$entity = $this->delete_process($uid);
// ๐ก ๋์ ์ผ๋ก ๊ฐ์ ธ์จ Entity ํด๋์ค ์ด๋ฆ์ผ๋ก instanceof ๊ฒ์ฌ
- $entityClass = $this->getEntityClass();
+ $entityClass = $this->service->getEntityClass();
if (!$entity instanceof $entityClass) {
throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ {$entityClass}๋ง ๊ฐ๋ฅ");
}
@@ -194,7 +191,7 @@ abstract class AbstractCRUDController extends AbstractWebController
$this->action_init_process($action);
$entity = $this->view_process($uid);
// ๐ก ๋์ ์ผ๋ก ๊ฐ์ ธ์จ Entity ํด๋์ค ์ด๋ฆ์ผ๋ก instanceof ๊ฒ์ฌ
- $entityClass = $this->getEntityClass();
+ $entityClass = $this->service->getEntityClass();
if (!$entity instanceof $entityClass) {
throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ {$entityClass}๋ง ๊ฐ๋ฅ");
}
diff --git a/app/Controllers/Admin/BoardController.php b/app/Controllers/Admin/BoardController.php
index 383fd11..7cab8a2 100644
--- a/app/Controllers/Admin/BoardController.php
+++ b/app/Controllers/Admin/BoardController.php
@@ -18,10 +18,6 @@ class BoardController extends AdminController
$this->addActionPaths('board');
}
//Action์์
๊ด๋ จ
- protected function getEntityClass(): string
- {
- return BoardEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
public function latest(string $category): ResponseInterface
diff --git a/app/Controllers/Admin/Customer/AccountController.php b/app/Controllers/Admin/Customer/AccountController.php
index 378b2c1..8b36c9b 100644
--- a/app/Controllers/Admin/Customer/AccountController.php
+++ b/app/Controllers/Admin/Customer/AccountController.php
@@ -17,10 +17,6 @@ class AccountController extends CustomerController
}
$this->addActionPaths('account');
}
- protected function getEntityClass(): string
- {
- return AccountEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
}
diff --git a/app/Controllers/Admin/Customer/ClientController.php b/app/Controllers/Admin/Customer/ClientController.php
index 1abf754..d17f56f 100644
--- a/app/Controllers/Admin/Customer/ClientController.php
+++ b/app/Controllers/Admin/Customer/ClientController.php
@@ -18,10 +18,6 @@ class ClientController extends CustomerController
}
$this->addActionPaths('client');
}
- protected function getEntityClass(): string
- {
- return ClientEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
//๊ณ ๊ฐ ์์ธ์ ๋ณด
diff --git a/app/Controllers/Admin/Customer/CouponController.php b/app/Controllers/Admin/Customer/CouponController.php
index 2724177..a62154a 100644
--- a/app/Controllers/Admin/Customer/CouponController.php
+++ b/app/Controllers/Admin/Customer/CouponController.php
@@ -17,10 +17,6 @@ class CouponController extends CustomerController
}
$this->addActionPaths('coupon');
}
- protected function getEntityClass(): string
- {
- return CouponEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
}
diff --git a/app/Controllers/Admin/Customer/PointController.php b/app/Controllers/Admin/Customer/PointController.php
index 3bcefe4..4b537a0 100644
--- a/app/Controllers/Admin/Customer/PointController.php
+++ b/app/Controllers/Admin/Customer/PointController.php
@@ -17,10 +17,6 @@ class PointController extends CustomerController
}
$this->addActionPaths('point');
}
- protected function getEntityClass(): string
- {
- return PointEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
}
diff --git a/app/Controllers/Admin/Customer/ServiceController.php b/app/Controllers/Admin/Customer/ServiceController.php
index 2dabcdd..b42833d 100644
--- a/app/Controllers/Admin/Customer/ServiceController.php
+++ b/app/Controllers/Admin/Customer/ServiceController.php
@@ -19,10 +19,6 @@ class ServiceController extends CustomerController
$this->addActionPaths('service');
$this->layouts['javascripts'][] = '';
}
- protected function getEntityClass(): string
- {
- return ServiceEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
public function create_form_process(array $formDatas = []): array
diff --git a/app/Controllers/Admin/Equipment/LineController.php b/app/Controllers/Admin/Equipment/LineController.php
index 19cfbbe..78541f6 100644
--- a/app/Controllers/Admin/Equipment/LineController.php
+++ b/app/Controllers/Admin/Equipment/LineController.php
@@ -18,10 +18,6 @@ class LineController extends EquipmentController
}
$this->addActionPaths('line');
}
- protected function getEntityClass(): string
- {
- return LineEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
}
diff --git a/app/Controllers/Admin/Equipment/ServerController.php b/app/Controllers/Admin/Equipment/ServerController.php
index 32d7a2f..d5a8e52 100644
--- a/app/Controllers/Admin/Equipment/ServerController.php
+++ b/app/Controllers/Admin/Equipment/ServerController.php
@@ -19,10 +19,6 @@ class ServerController extends EquipmentController
$this->addActionPaths('server');
$this->layouts['javascripts'][] = '';
}
- protected function getEntityClass(): string
- {
- return ServerEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
public function create_form_process(array $formDatas = []): array
diff --git a/app/Controllers/Admin/Equipment/ServerPartController.php b/app/Controllers/Admin/Equipment/ServerPartController.php
index dcd6cd3..e43e18d 100644
--- a/app/Controllers/Admin/Equipment/ServerPartController.php
+++ b/app/Controllers/Admin/Equipment/ServerPartController.php
@@ -17,10 +17,6 @@ class ServerPartController extends EquipmentController
}
$this->addActionPaths('serverpart');
}
- protected function getEntityClass(): string
- {
- return ServerPartEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
protected function create_form_process(array $formDatas = []): array
diff --git a/app/Controllers/Admin/MylogController.php b/app/Controllers/Admin/MylogController.php
index 1b9857e..366426e 100644
--- a/app/Controllers/Admin/MylogController.php
+++ b/app/Controllers/Admin/MylogController.php
@@ -17,10 +17,6 @@ class MylogController extends AdminController
}
$this->addActionPaths('mylog');
}
- protected function getEntityClass(): string
- {
- return MylogEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
}
diff --git a/app/Controllers/Admin/Part/CPUController.php b/app/Controllers/Admin/Part/CPUController.php
index dda0192..96d14ff 100644
--- a/app/Controllers/Admin/Part/CPUController.php
+++ b/app/Controllers/Admin/Part/CPUController.php
@@ -17,10 +17,6 @@ class CPUController extends PartController
}
$this->addActionPaths('cpu');
}
- protected function getEntityClass(): string
- {
- return CPUEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
}
diff --git a/app/Controllers/Admin/Part/CSController.php b/app/Controllers/Admin/Part/CSController.php
index fbb9f8f..527a27f 100644
--- a/app/Controllers/Admin/Part/CSController.php
+++ b/app/Controllers/Admin/Part/CSController.php
@@ -17,10 +17,6 @@ class CSController extends PartController
}
$this->addActionPaths('cs');
}
- protected function getEntityClass(): string
- {
- return CSEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
}
diff --git a/app/Controllers/Admin/Part/DISKController.php b/app/Controllers/Admin/Part/DISKController.php
index a4b5734..b5be075 100644
--- a/app/Controllers/Admin/Part/DISKController.php
+++ b/app/Controllers/Admin/Part/DISKController.php
@@ -17,10 +17,6 @@ class DISKController extends PartController
}
$this->addActionPaths('disk');
}
- protected function getEntityClass(): string
- {
- return DISKEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
}
diff --git a/app/Controllers/Admin/Part/IPController.php b/app/Controllers/Admin/Part/IPController.php
index 2b2db53..a3a7365 100644
--- a/app/Controllers/Admin/Part/IPController.php
+++ b/app/Controllers/Admin/Part/IPController.php
@@ -17,10 +17,6 @@ class IPController extends PartController
}
$this->addActionPaths('ip');
}
- protected function getEntityClass(): string
- {
- return IPEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
}
diff --git a/app/Controllers/Admin/Part/RAMController.php b/app/Controllers/Admin/Part/RAMController.php
index 10c5f7e..7c68fa6 100644
--- a/app/Controllers/Admin/Part/RAMController.php
+++ b/app/Controllers/Admin/Part/RAMController.php
@@ -17,10 +17,6 @@ class RAMController extends PartController
}
$this->addActionPaths('ram');
}
- protected function getEntityClass(): string
- {
- return RAMEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
}
diff --git a/app/Controllers/Admin/Part/SOFTWAREController.php b/app/Controllers/Admin/Part/SOFTWAREController.php
index 970d527..6f41b0f 100644
--- a/app/Controllers/Admin/Part/SOFTWAREController.php
+++ b/app/Controllers/Admin/Part/SOFTWAREController.php
@@ -17,10 +17,6 @@ class SOFTWAREController extends PartController
}
$this->addActionPaths('software');
}
- protected function getEntityClass(): string
- {
- return SOFTWAREEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
}
diff --git a/app/Controllers/Admin/Part/SWITCHController.php b/app/Controllers/Admin/Part/SWITCHController.php
index cd346bb..4fad598 100644
--- a/app/Controllers/Admin/Part/SWITCHController.php
+++ b/app/Controllers/Admin/Part/SWITCHController.php
@@ -17,10 +17,6 @@ class SWITCHController extends PartController
}
$this->addActionPaths('switch');
}
- protected function getEntityClass(): string
- {
- return SWITCHEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
}
diff --git a/app/Controllers/Admin/PaymentController.php b/app/Controllers/Admin/PaymentController.php
index 252cc4c..17884e1 100644
--- a/app/Controllers/Admin/PaymentController.php
+++ b/app/Controllers/Admin/PaymentController.php
@@ -21,10 +21,6 @@ class PaymentController extends AdminController
$this->addActionPaths('payment');
}
//Action์์
๊ด๋ จ
- protected function getEntityClass(): string
- {
- return PaymentEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
//์ผํ์ฑ ์ถ๊ฐ์ฉ
diff --git a/app/Controllers/Admin/SearchController.php b/app/Controllers/Admin/SearchController.php
index 0f9a35f..b3cab2d 100644
--- a/app/Controllers/Admin/SearchController.php
+++ b/app/Controllers/Admin/SearchController.php
@@ -18,10 +18,6 @@ class SearchController extends AdminController
$this->addActionPaths('service');
}
//Action์์
๊ด๋ จ
- protected function getEntityClass(): string
- {
- return ServiceEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
protected function index_entities_process(array $entities = []): array
diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php
index 3a4810c..2133e3a 100644
--- a/app/Controllers/Admin/UserController.php
+++ b/app/Controllers/Admin/UserController.php
@@ -18,10 +18,6 @@ class UserController extends AdminController
$this->addActionPaths('user');
}
//Action์์
๊ด๋ จ
- protected function getEntityClass(): string
- {
- return UserEntity::class;
- }
//๊ธฐ๋ณธ ํจ์ ์์
//Custom ์ถ๊ฐ ํจ์
}
diff --git a/app/Entities/Part/CPUEntity.php b/app/Entities/Part/CPUEntity.php
index c2fb329..f06a181 100644
--- a/app/Entities/Part/CPUEntity.php
+++ b/app/Entities/Part/CPUEntity.php
@@ -9,15 +9,15 @@ class CPUEntity extends PartEntity
const PK = CPUModel::PK;
const TITLE = CPUModel::TITLE;
//๊ธฐ๋ณธ๊ธฐ๋ฅ
- final public function getUsed(): int
- {
- return $this->attributes['used'];
- }
- final public function getStock(): int
+ public function getStock(): int
{
return $this->attributes['stock'];
}
- final public function getAvailable(): int
+ public function getUsed(): int
+ {
+ return $this->attributes['used'];
+ }
+ public function getAvailable(): int
{
return $this->getStock() - $this->getUsed();
}
diff --git a/app/Entities/Part/CSEntity.php b/app/Entities/Part/CSEntity.php
index c90f625..bee94fb 100644
--- a/app/Entities/Part/CSEntity.php
+++ b/app/Entities/Part/CSEntity.php
@@ -22,4 +22,13 @@ class CSEntity extends PartEntity
{
return $this->attributes['domain'] ?? null;
}
+ //abstract ์ ์ธ์ฒ๋ฆฌ์ฉ
+ public function getUsed(): int
+ {
+ return 0;
+ }
+ public function getAvailable(): int
+ {
+ return 0;
+ }
}
diff --git a/app/Entities/Part/DISKEntity.php b/app/Entities/Part/DISKEntity.php
index 71ef342..32e63c4 100644
--- a/app/Entities/Part/DISKEntity.php
+++ b/app/Entities/Part/DISKEntity.php
@@ -9,11 +9,7 @@ class DISKEntity extends PartEntity
const PK = DISKModel::PK;
const TITLE = DISKModel::TITLE;
//๊ธฐ๋ณธ๊ธฐ๋ฅ
- final public function getUsed(): int
- {
- return $this->attributes['used'];
- }
- final public function getStock(): int
+ public function getStock(): int
{
return $this->attributes['stock'];
}
@@ -21,7 +17,11 @@ class DISKEntity extends PartEntity
{
return intval($this->attributes['format'] ?? 0);
}
- final public function getAvailable(): int
+ public function getUsed(): int
+ {
+ return $this->attributes['used'];
+ }
+ public function getAvailable(): int
{
return $this->getStock() - $this->getUsed() - $this->getFormat();
}
diff --git a/app/Entities/Part/IPEntity.php b/app/Entities/Part/IPEntity.php
index df57edf..9f342fd 100644
--- a/app/Entities/Part/IPEntity.php
+++ b/app/Entities/Part/IPEntity.php
@@ -8,11 +8,11 @@ class IPEntity extends PartEntity
{
const PK = IPModel::PK;
const TITLE = IPModel::TITLE;
- final public function getLineInfoUID(): int|null
+ public function getLineInfoUID(): int|null
{
return $this->attributes['lineinfo_uid'] ?? null;
}
- final public function getOldClientInfoUID(): int|null
+ public function getOldClientInfoUID(): int|null
{
return $this->attributes['old_clientinfo_uid'] ?? null;
}
@@ -21,4 +21,13 @@ class IPEntity extends PartEntity
{
return $this->attributes['ip'];
}
+ //abstract ์ ์ธ์ฒ๋ฆฌ์ฉ
+ public function getUsed(): int
+ {
+ return 0;
+ }
+ public function getAvailable(): int
+ {
+ return 0;
+ }
}
diff --git a/app/Entities/Part/PartEntity.php b/app/Entities/Part/PartEntity.php
index b51531b..e242a2b 100644
--- a/app/Entities/Part/PartEntity.php
+++ b/app/Entities/Part/PartEntity.php
@@ -10,6 +10,8 @@ abstract class PartEntity extends CommonEntity
{
parent::__construct($data);
}
+ abstract public function getAvailable(): int;
+ abstract public function getUsed(): int;
final public function getClientInfoUID(): int|null
{
return $this->attributes['clientinfo_uid'];
diff --git a/app/Entities/Part/RAMEntity.php b/app/Entities/Part/RAMEntity.php
index 7d36257..70a1316 100644
--- a/app/Entities/Part/RAMEntity.php
+++ b/app/Entities/Part/RAMEntity.php
@@ -9,15 +9,15 @@ class RAMEntity extends PartEntity
const PK = RAMModel::PK;
const TITLE = RAMModel::TITLE;
//๊ธฐ๋ณธ๊ธฐ๋ฅ
- final public function getUsed(): int
- {
- return $this->attributes['used'];
- }
- final public function getStock(): int
+ public function getStock(): int
{
return $this->attributes['stock'];
}
- final public function getAvailable(): int
+ public function getUsed(): int
+ {
+ return $this->attributes['used'];
+ }
+ public function getAvailable(): int
{
return $this->getStock() - $this->getUsed();
}
diff --git a/app/Entities/Part/SOFTWAREEntity.php b/app/Entities/Part/SOFTWAREEntity.php
index 2d9ec46..5d66d14 100644
--- a/app/Entities/Part/SOFTWAREEntity.php
+++ b/app/Entities/Part/SOFTWAREEntity.php
@@ -9,15 +9,15 @@ class SOFTWAREEntity extends PartEntity
const PK = SOFTWAREModel::PK;
const TITLE = SOFTWAREModel::TITLE;
//๊ธฐ๋ณธ๊ธฐ๋ฅ
- final public function getUsed(): int
- {
- return $this->attributes['used'];
- }
- final public function getStock(): int
+ public function getStock(): int
{
return $this->attributes['stock'];
}
- final public function getAvailable(): int
+ public function getUsed(): int
+ {
+ return $this->attributes['used'];
+ }
+ public function getAvailable(): int
{
return $this->getStock() - $this->getUsed();
}
diff --git a/app/Entities/Part/SWITCHEntity.php b/app/Entities/Part/SWITCHEntity.php
index beb334e..cd2d263 100644
--- a/app/Entities/Part/SWITCHEntity.php
+++ b/app/Entities/Part/SWITCHEntity.php
@@ -8,8 +8,17 @@ class SWITCHEntity extends PartEntity
{
const PK = SWITCHModel::PK;
const TITLE = SWITCHModel::TITLE;
- final public function getCode(): string
+ public function getCode(): string
{
return $this->attributes['code'] ?? "";
}
+ //abstract ์ ์ธ์ฒ๋ฆฌ์ฉ
+ public function getUsed(): int
+ {
+ return 0;
+ }
+ public function getAvailable(): int
+ {
+ return 0;
+ }
}
diff --git a/app/Services/BoardService.php b/app/Services/BoardService.php
index 47f40e1..aa2c004 100644
--- a/app/Services/BoardService.php
+++ b/app/Services/BoardService.php
@@ -7,6 +7,7 @@ use App\Entities\BoardEntity;
use App\Forms\BoardForm;
use App\Helpers\BoardHelper;
use App\Models\BoardModel;
+use RuntimeException;
class BoardService extends CommonService
{
@@ -25,6 +26,10 @@ class BoardService extends CommonService
{
return new BoardDTO($formDatas);
}
+ public function getEntityClass(): string
+ {
+ return BoardEntity::class;
+ }
public function getFormService(): BoardForm
{
if ($this->_form === null) {
@@ -122,11 +127,19 @@ class BoardService extends CommonService
}
protected function create_process(array $formDatas): BoardEntity
{
- return new BoardEntity($formDatas);
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof BoardEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ BoardEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
protected function modify_process($uid, array $formDatas): BoardEntity
{
- return parent::modify_process($uid, $formDatas);
+ $entity = parent::modify_process($uid, $formDatas);
+ if (!$entity instanceof BoardEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ BoardEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
//List ๊ฒ์์ฉ
//FormFilter ์กฐ๊ฑด์ ์ฒ๋ฆฌ
diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php
index 5569321..cb146b6 100644
--- a/app/Services/CommonService.php
+++ b/app/Services/CommonService.php
@@ -18,8 +18,10 @@ abstract class CommonService
private array $_classPaths = [];
protected $title = null;
protected function __construct(protected CommonModel $model) {}
+ abstract public function action_init_process(string $action, array $formDatas = []): void;
abstract protected function getDTOClass(): string;
abstract public function createDTO(array $formDatas): CommonDTO;
+ abstract public function getEntityClass(): string;
abstract public function getFormService(): mixed;
abstract public function getHelper(): mixed;
final protected function addClassPaths(string $path): void
@@ -30,12 +32,17 @@ abstract class CommonService
{
return $isArray ? $this->_classPaths : implode($delimeter, $this->_classPaths);
}
- abstract public function action_init_process(string $action, array $formDatas = []): void;
+ final public function getNextPK(): int
+ {
+ $pkField = $this->model->getPKField();
+ $row = $this->model->selectMax($pkField)->get()->getRow();
+ return isset($row->{$pkField}) ? ((int)$row->{$pkField} + 1) : 1;
+ }
/**
* ๋จ์ผ ์ํฐํฐ๋ฅผ ์กฐํํฉ๋๋ค.
* @return CommonEntity|null CommonEntity ์ธ์คํด์ค ๋๋ ์ฐพ์ง ๋ชปํ์ ๊ฒฝ์ฐ null
*/
- final public function getEntity(string|int|array $where, ?string $message = null): ?CommonEntity
+ public function getEntity(string|int|array $where, ?string $message = null): ?CommonEntity
{
try {
$entity = is_array($where) ? $this->model->where($where)->first() : $this->model->find($where);
@@ -64,7 +71,7 @@ abstract class CommonService
throw new \Exception($errorMessage, $e->getCode(), $e);
}
}
- final public function getEntities(?array $where = null, array $columns = ['*']): array
+ public function getEntities(?array $where = null, array $columns = ['*']): array
{
try {
$entities = $this->getEntities_process($where, $columns);
@@ -88,13 +95,6 @@ abstract class CommonService
throw new \Exception($errorMessage, $e->getCode(), $e);
}
}
- final public function getNextPK(): int
- {
- $pkField = $this->model->getPKField();
- $row = $this->model->selectMax($pkField)->get()->getRow();
- return isset($row->{$pkField}) ? ((int)$row->{$pkField} + 1) : 1;
- }
-
//Entity๊ด๋ จ
protected function getEntity_process(CommonEntity $entity): CommonEntity
{
@@ -153,16 +153,23 @@ abstract class CommonService
// INSERT ์ Entity์ PK๋ 0 ๋๋ NULL์ด์ด์ผ ํจ (DB๊ฐ ID๋ฅผ ์์ฑํ๋๋ก)
$initialPK = $entity->getPK();
$result = $this->model->save($entity);
-
// ์ต์ข
์ ์ผ๋ก DB์ ๋ฐ์๋ PK๋ฅผ ๋ฐํ๋ฐ์ต๋๋ค. (UPDATE์ด๋ฉด ๊ธฐ์กด PK, INSERT์ด๋ฉด ์ PK)
$finalPK = $this->handle_save_result($result, $initialPK);
-
// handle_save_result์์ ํ์ธ๋ ์ต์ข
PK๋ฅผ ์ฌ์ฉํ์ฌ DB์์ ์ต์ ์ํฐํฐ๋ฅผ ๊ฐ์ ธ์ด
return $this->getEntity($finalPK);
}
//์์ฑ์ฉ
- abstract protected function create_process(array $formDatas): CommonEntity;
+ protected function create_process(array $formDatas): CommonEntity
+ {
+ // ๐ก ๋์ ์ผ๋ก ๊ฐ์ ธ์จ Entity ํด๋์ค ์ด๋ฆ์ผ๋ก instanceof ๊ฒ์ฌ
+ $entityClass = $this->getEntityClass();
+ $entity = new $entityClass($formDatas);
+ if (!$entity instanceof $entityClass) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ {$entityClass}๋ง ๊ฐ๋ฅ");
+ }
+ return $this->save_process($entity);
+ }
final public function create(object $dto): CommonEntity
{
//DTO ํ์
์ฒดํฌ ๋ก์ง์ ์ผ๋ฐํ
@@ -170,15 +177,13 @@ abstract class CommonService
if (!$dto instanceof $dtoClass) {
throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์: " . get_class($dto) . "๋ ์ฌ์ฉํ ์ ์์ต๋๋ค. ({$dtoClass} ํ์)");
}
-
$formDatas = $dto->toArray();
if (!$this->getFormService()->validate($formDatas)) {
throw new ValidationException(implode("\n", service('validation')->getErrors()));
}
// NOTE: create_process์์ ์ํฐํฐ๋ฅผ ์์ฑํ ๋, ์๋ ์ฆ๊ฐ(AUTO_INCREMENT) ํ๋๋
// DB๊ฐ ์ฒ๋ฆฌํ๋๋ก NULL์ด๋ ๋น ๊ฐ(0)์ผ๋ก ๋๋ ๊ฒ์ด ์ผ๋ฐ์ ์
๋๋ค.
- $entity = $this->create_process($formDatas);
- return $this->save_process($entity);
+ return $this->create_process($formDatas);
}
//์์ ์ฉ
@@ -188,17 +193,13 @@ abstract class CommonService
if (!$entity) {
throw new \Exception(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์: {$uid}์ ํด๋นํ๋ ์ ๋ณด์ ์ฐพ์์ ์์ต๋๋ค.");
}
-
$pkField = $this->model->getPKField();
-
// DTO ๋ฐ์ดํฐ์์ PK ํ๋๊ฐ ์๋ค๋ฉด ์ ๊ฑฐํ์ฌ, fill()์์ ๊ธฐ์กด PK๋ฅผ ๋ฎ์ด์ฐ์ง ์๋๋ก ํฉ๋๋ค.
if (isset($formDatas[$pkField])) {
unset($formDatas[$pkField]);
}
-
// 1. ๋ฐ์ดํฐ๋ฅผ Entity์ ์ฑ์๋๋ค.
$entity->fill($formDatas);
-
// 2. (ํต์ฌ ๋ฐฉ์ด) fill() ์์
์ด Entity์ PK๋ฅผ ํผ์ํ๋๋ผ๋,
// ๊ธฐ์กด $uid ๊ฐ์ ์ฌ์ฉํ์ฌ Entity์ PK๋ฅผ ๊ฐ์ ๋ก ๋ณต์ํฉ๋๋ค.
// ์ด๊ฒ์ด Model::save()๊ฐ UPDATE๋ฅผ ์คํํ๋๋ก ๋ณด์ฅํ๋ ์ต์ข
๋ฐฉ์ด์ ์
๋๋ค.
@@ -207,10 +208,8 @@ abstract class CommonService
log_message('warning', "modify_process: Entity PK ํผ์ ๊ฐ์ง. '{$currentPK}' ๋์ ์๋ณธ UID '{$uid}'๋ก ๊ฐ์ ๋ณต์.");
$entity->{$pkField} = $uid;
}
-
log_message('debug', "save_process ์ง์
์ Entity PK: " . $entity->getPK() . " (๊ธฐ๋๊ฐ: {$uid})");
-
- return $entity;
+ return $this->save_process($entity);
}
final public function modify(string|int $uid, object $dto): CommonEntity
{
@@ -219,13 +218,11 @@ abstract class CommonService
if (!$dto instanceof $dtoClass) {
throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์: " . get_class($dto) . "๋ ์ฌ์ฉํ ์ ์์ต๋๋ค. ({$dtoClass} ํ์)");
}
-
$formDatas = $dto->toArray();
if (!$this->getFormService()->validate($formDatas)) {
throw new ValidationException(implode("\n", service('validation')->getErrors()));
}
- $entity = $this->modify_process($uid, $formDatas);
- return $this->save_process($entity);
+ return $this->modify_process($uid, $formDatas);
}
//๋ฐฐ์น ์์
์ฉ ์์
@@ -247,8 +244,7 @@ abstract class CommonService
if (!$this->getFormService()->validate($formDatas)) {
throw new ValidationException(implode("\n", service('validation')->getErrors()));
}
- $entity = $this->batchjob_process($uid, $formDatas);
- return $this->save_process($entity);
+ return $this->batchjob_process($uid, $formDatas);
}
//์ญ์ ์ฉ (์ผ๋ฐ)
@@ -287,7 +283,6 @@ abstract class CommonService
final public function batchjob_delete(string|int $uid): CommonEntity
{
$entity = $this->batchjob_delete_process($uid);
-
$result = $this->model->delete($entity->getPK());
log_message('debug', $this->model->getLastQuery());
if ($result === false) {
diff --git a/app/Services/Customer/AccountService.php b/app/Services/Customer/AccountService.php
index ac1bca0..3c4d8b9 100644
--- a/app/Services/Customer/AccountService.php
+++ b/app/Services/Customer/AccountService.php
@@ -26,6 +26,10 @@ class AccountService extends CustomerService
{
return new AccountDTO($formDatas);
}
+ public function getEntityClass(): string
+ {
+ return AccountEntity::class;
+ }
public function getFormService(): AccountForm
{
if ($this->_form === null) {
@@ -112,7 +116,11 @@ class AccountService extends CustomerService
}
protected function create_process(array $formDatas): AccountEntity
{
- return new AccountEntity($formDatas);
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof AccountEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ AccountEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
protected function modify_process($uid, array $formDatas): AccountEntity
{
diff --git a/app/Services/Customer/ClientService.php b/app/Services/Customer/ClientService.php
index 97a1413..2fa2aa6 100644
--- a/app/Services/Customer/ClientService.php
+++ b/app/Services/Customer/ClientService.php
@@ -26,6 +26,10 @@ class ClientService extends CustomerService
{
return new ClientDTO($formDatas);
}
+ public function getEntityClass(): string
+ {
+ return ClientEntity::class;
+ }
public function getFormService(): ClientForm
{
if ($this->_form === null) {
@@ -112,7 +116,11 @@ class ClientService extends CustomerService
}
protected function create_process(array $formDatas): ClientEntity
{
- return new ClientEntity($formDatas);
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof ClientEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ ClientEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
protected function modify_process($uid, array $formDatas): ClientEntity
{
diff --git a/app/Services/Customer/CouponService.php b/app/Services/Customer/CouponService.php
index 2688630..d5a1542 100644
--- a/app/Services/Customer/CouponService.php
+++ b/app/Services/Customer/CouponService.php
@@ -26,6 +26,10 @@ class CouponService extends CustomerService
{
return new CouponDTO($formDatas);
}
+ public function getEntityClass(): string
+ {
+ return CouponEntity::class;
+ }
public function getFormService(): CouponForm
{
if ($this->_form === null) {
@@ -103,7 +107,11 @@ class CouponService extends CustomerService
}
protected function create_process(array $formDatas): CouponEntity
{
- return new CouponEntity($formDatas);
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof CouponEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ CouponEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
protected function modify_process($uid, array $formDatas): CouponEntity
{
diff --git a/app/Services/Customer/PointService.php b/app/Services/Customer/PointService.php
index 544ac0a..a7cf1bd 100644
--- a/app/Services/Customer/PointService.php
+++ b/app/Services/Customer/PointService.php
@@ -26,6 +26,10 @@ class PointService extends CustomerService
{
return new PointDTO($formDatas);
}
+ public function getEntityClass(): string
+ {
+ return PointEntity::class;
+ }
public function getFormService(): PointForm
{
if ($this->_form === null) {
@@ -103,7 +107,11 @@ class PointService extends CustomerService
}
protected function create_process(array $formDatas): PointEntity
{
- return new PointEntity($formDatas);
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof PointEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ PointEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
protected function modify_process($uid, array $formDatas): PointEntity
{
diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php
index 60307eb..ca42884 100644
--- a/app/Services/Customer/ServiceService.php
+++ b/app/Services/Customer/ServiceService.php
@@ -28,6 +28,10 @@ class ServiceService extends CustomerService
{
return new ServiceDTO($formDatas);
}
+ public function getEntityClass(): string
+ {
+ return ServiceEntity::class;
+ }
public function getFormService(): ServiceForm
{
if ($this->_form === null) {
@@ -129,7 +133,11 @@ class ServiceService extends CustomerService
}
protected function create_process(array $formDatas): ServiceEntity
{
- return new ServiceEntity($formDatas);
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof ServiceEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ ServiceEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
protected function modify_process($uid, array $formDatas): ServiceEntity
{
diff --git a/app/Services/Equipment/LineService.php b/app/Services/Equipment/LineService.php
index 90012c1..99ce2bc 100644
--- a/app/Services/Equipment/LineService.php
+++ b/app/Services/Equipment/LineService.php
@@ -26,6 +26,10 @@ class LineService extends EquipmentService
{
return new LineDTO($formDatas);
}
+ public function getEntityClass(): string
+ {
+ return LineEntity::class;
+ }
public function getFormService(): LineForm
{
if ($this->_form === null) {
@@ -98,7 +102,11 @@ class LineService extends EquipmentService
}
protected function create_process(array $formDatas): LineEntity
{
- return new LineEntity($formDatas);
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof LineEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ LineEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
protected function modify_process($uid, array $formDatas): LineEntity
{
diff --git a/app/Services/Equipment/ServerPartService.php b/app/Services/Equipment/ServerPartService.php
index 26e8a23..c0fc70b 100644
--- a/app/Services/Equipment/ServerPartService.php
+++ b/app/Services/Equipment/ServerPartService.php
@@ -3,12 +3,13 @@
namespace App\Services\Equipment;
use App\DTOs\Equipment\ServerPartDTO;
-use App\DTOs\UserDTO;
+use App\Entities\Equipment\ServerEntity;
use App\Entities\Equipment\ServerPartEntity;
+use App\Entities\Part\PartEntity;
use App\Forms\Equipment\ServerPartForm;
use App\Helpers\Equipment\ServerPartHelper;
use App\Models\Equipment\ServerPartModel;
-use App\Services\CommonService;
+use App\Services\Part\PartService;
use RuntimeException;
class ServerPartService extends EquipmentService
@@ -28,6 +29,10 @@ class ServerPartService extends EquipmentService
{
return new ServerPartDTO($formDatas);
}
+ public function getEntityClass(): string
+ {
+ return ServerPartEntity::class;
+ }
public function getFormService(): ServerPartForm
{
if ($this->_form === null) {
@@ -100,33 +105,40 @@ class ServerPartService extends EquipmentService
$this->getFormService()->setIndexFilters($indexFilter);
$this->getFormService()->setBatchjobFilters($batchjobFilters);
}
- //๊ธฐ๋ณธ ๊ธฐ๋ฅ๋ถ๋ถ
- private function getPartService(string $type): CommonService
+ //๊ฐ ํํธ๋ณ ์๋น์ค
+ private function getPartService(string $type): PartService
{
return service('part_' . strtolower($type) . 'service');
}
+ //๊ธฐ๋ณธ ๊ธฐ๋ฅ๋ถ๋ถ
protected function getEntity_process(mixed $entity): ServerPartEntity
{
return $entity;
}
protected function create_process(array $formDatas): ServerPartEntity
{
- if (!array_key_exists('title', $formDatas)) {
- if (!array_key_exists('type', $formDatas)) {
- throw new \Exception(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:๋ถํํ์์ด ์ง์ ๋์ง ์์์ต๋๋ค.");
- }
- $formDatas['title'] = $this->getPartService($formDatas['type']->getTitle());
+ if (!array_key_exists('type', $formDatas)) {
+ throw new \Exception(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:๋ถํํ์์ด ์ง์ ๋์ง ์์์ต๋๋ค.");
}
- return new ServerPartEntity($formDatas);
+ //๊ฐ ํํธ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
+ $partEntity = $this->getPartService($formDatas['type'])->getEntity($formDatas['part_uid']);
+ //์๋ฒํํธ์ ๋ณด Title ์ค์ ์ฉ
+ $formDatas['title'] = $partEntity->getTitle();
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof ServerPartEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ ServerPartEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
protected function modify_process($uid, array $formDatas): ServerPartEntity
{
- if (!array_key_exists('title', $formDatas)) {
- if (!array_key_exists('type', $formDatas)) {
- throw new \Exception(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:๋ถํํ์์ด ์ง์ ๋์ง ์์์ต๋๋ค.");
- }
- $formDatas['title'] = $this->getPartService($formDatas['type']->getTitle());
+ if (!array_key_exists('type', $formDatas)) {
+ throw new \Exception(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:๋ถํํ์์ด ์ง์ ๋์ง ์์์ต๋๋ค.");
}
+ //๊ฐ ํํธ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
+ $partEntity = $this->getPartService($formDatas['type'])->getEntity($formDatas['part_uid']);
+ //์๋ฒํํธ์ ๋ณด Title ์ค์ ์ฉ
+ $formDatas['title'] = $partEntity->getTitle();
$entity = parent::modify_process($uid, $formDatas);
if (!$entity instanceof ServerPartEntity) {
throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ ServerPartEntity๋ง ๊ฐ๋ฅ");
@@ -136,4 +148,34 @@ class ServerPartService extends EquipmentService
//List ๊ฒ์์ฉ
//FormFilter ์กฐ๊ฑด์ ์ฒ๋ฆฌ
//๊ฒ์์ด์กฐ๊ฑด์ ์ฒ๋ฆฌ
+
+ //์๋ฒ์ถ๊ฐ์ ์๋ฒํํธ ์๋์ถ๊ฐ์ฉ
+ public function attachToServer(ServerEntity $serverEntity): void
+ {
+ //*์๋ฒ์ Title ๋์๋ฌธ์๊ตฌ๋ถ ํ์->์๋ฒ์ Title๋ก ๊ตฌ๋ถํด์ ๊ธฐ๋ณธ๋ถํ ์ถ๊ฐ
+ foreach (SERVERPART['SERVER_PARTTYPES'] as $parttype) {
+ //ํด๋น server_type์ ์ ์๋ ์์๊ฐ์ด ์์ผ๋ฉด
+ if (array_key_exists($serverEntity->getTitle(), SERVERPART[$parttype])) {
+ foreach (SERVERPART[$parttype][$serverEntity->getTitle()] as $part) {
+ //ํด๋น ํํธ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
+ $partEntity = $this->getPartService($parttype)->getEntity($part['UID']);
+ if (!$partEntity instanceof PartEntity) {
+ throw new \Exception(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์: {$part['UID']} ์๋ฒ ์ ๋ณด๋ฅผ ์ฐพ์์ ์์ต๋๋ค.");
+ }
+ //์๋ฒํํธ์ ๋ณด ์์ฑ
+ $formDatas = [];
+ $formDatas['serverinfo_uid'] = $serverEntity->getPK();
+ $formDatas["part_uid"] = $partEntity->getPK();
+ $formDatas['billing'] = PAYMENT['BILLING']['BASE'];
+ $formDatas['type'] = $parttype;
+ $formDatas['title'] = $partEntity->getTitle(); //ํํธ ์ ๋ชฉ
+ $formDatas['amount'] = $partEntity->getPrice(); //ํํธ ๊ธ์ก
+ $formDatas['cnt'] = $part["CNT"];
+ $formDatas['extra'] = $part["EXTRA"];
+ $entity = $this->model->create($formDatas);
+ $this->getPartService($entity->getType())->attachToServerPart($entity);
+ }
+ }
+ }
+ }
}
diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php
index 7055cbf..49002fd 100644
--- a/app/Services/Equipment/ServerService.php
+++ b/app/Services/Equipment/ServerService.php
@@ -26,6 +26,10 @@ class ServerService extends EquipmentService
{
return new ServerDTO($formDatas);
}
+ public function getEntityClass(): string
+ {
+ return ServerEntity::class;
+ }
public function getFormService(): ServerForm
{
if ($this->_form === null) {
@@ -120,7 +124,13 @@ class ServerService extends EquipmentService
}
protected function create_process(array $formDatas): ServerEntity
{
- return new ServerEntity($formDatas);
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof ServerEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ ServerEntity๋ง ๊ฐ๋ฅ");
+ }
+ //์๋ฒ์ถ๊ฐ์ ์๋ฒํํธ ์๋์ถ๊ฐ์ฉ
+ service('equipment_serverpartservice')->attachToServer($entity);
+ return $entity;
}
protected function modify_process($uid, array $formDatas): ServerEntity
{
diff --git a/app/Services/MylogService.php b/app/Services/MylogService.php
index 6e83282..996f6df 100644
--- a/app/Services/MylogService.php
+++ b/app/Services/MylogService.php
@@ -28,6 +28,10 @@ class MylogService extends CommonService implements PipelineStepInterface
{
return new MylogDTO($formDatas);
}
+ public function getEntityClass(): string
+ {
+ return MylogEntity::class;
+ }
public function getFormService(): MylogForm
{
if ($this->_form === null) {
@@ -113,10 +117,18 @@ class MylogService extends CommonService implements PipelineStepInterface
}
protected function create_process(array $formDatas): MylogEntity
{
- return new MylogEntity($formDatas);
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof MylogEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ MylogEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
- protected function modify_process($uid, array $formDatas): MyLogEntity
+ protected function modify_process($uid, array $formDatas): MylogEntity
{
- return parent::modify_process($uid, $formDatas);
+ $entity = parent::modify_process($uid, $formDatas);
+ if (!$entity instanceof MylogEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ MylogEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
}
diff --git a/app/Services/Part/CPUService.php b/app/Services/Part/CPUService.php
index 71769ba..8754c46 100644
--- a/app/Services/Part/CPUService.php
+++ b/app/Services/Part/CPUService.php
@@ -26,6 +26,10 @@ class CPUService extends PartService
{
return new CPUDTO($formDatas);
}
+ public function getEntityClass(): string
+ {
+ return CPUEntity::class;
+ }
public function getFormService(): CPUForm
{
if ($this->_form === null) {
@@ -95,7 +99,11 @@ class CPUService extends PartService
}
protected function create_process(array $formDatas): CPUEntity
{
- return new CPUEntity($formDatas);
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof CPUEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ CPUEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
protected function modify_process($uid, array $formDatas): CPUEntity
{
@@ -108,4 +116,10 @@ class CPUService extends PartService
//List ๊ฒ์์ฉ
//FormFilter ์กฐ๊ฑด์ ์ฒ๋ฆฌ
//๊ฒ์์ด์กฐ๊ฑด์ ์ฒ๋ฆฌ
+ //OrderBy ์ฒ๋ฆฌ
+ public function setOrderBy(mixed $field = null, mixed $value = null): void
+ {
+ $this->model->orderBy('title ASC');
+ parent::setOrderBy($field, $value);
+ }
}
diff --git a/app/Services/Part/CSService.php b/app/Services/Part/CSService.php
index b905445..ad89125 100644
--- a/app/Services/Part/CSService.php
+++ b/app/Services/Part/CSService.php
@@ -3,6 +3,7 @@
namespace App\Services\Part;
use App\DTOs\Part\CSDTO;
+use App\Entities\Equipment\ServerPartEntity;
use App\Entities\Part\CSEntity;
use App\Forms\Part\CSForm;
use App\Helpers\Part\CSHelper;
@@ -26,6 +27,10 @@ class CSService extends PartService
{
return new CSDTO($formDatas);
}
+ public function getEntityClass(): string
+ {
+ return CSEntity::class;
+ }
public function getFormService(): CSForm
{
if ($this->_form === null) {
@@ -122,7 +127,11 @@ class CSService extends PartService
}
protected function create_process(array $formDatas): CSEntity
{
- return new CSEntity($formDatas);
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof CSEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ CSEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
protected function modify_process($uid, array $formDatas): CSEntity
{
@@ -141,4 +150,49 @@ class CSService extends PartService
$this->model->orderBy("INET_ATON(ip) ASC");
parent::setOrderBy($field, $value);
}
+
+ //์๋ฒํํธ๊ด๋ จ ์์
+ public function attachToServerPart(ServerPartEntity $serverPartEntity): CSEntity
+ {
+ $formDatas = [];
+ $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID();
+ $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID();
+ $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID();
+ $formDatas['status'] = STATUS['OCCUPIED'];
+ if (!array_key_exists('status', $formDatas)) {
+ throw new \Exception(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์: CS์ํ๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.");
+ }
+ //CS์ ๋ณด๊ฐ์ ธ์ค๊ธฐ
+ $entity = $this->getEntity($serverPartEntity->getPartUID());
+ if (!$entity instanceof CSEntity) {
+ throw new \Exception(message: "{$serverPartEntity->getPartUID()}์ ํด๋นํ๋ CS์ ๋ณด๋ฅผ ์ฐพ์์์์ต๋๋ค.");
+ }
+ //CS์ ๋ณด์์ ํด๋นํ๋ CS๊ฐ ์์ผ๋ฉด ๊ฐ์ ธ์์ ์ฌ์ฉ์ค์ธ์ง ์ฒดํฌ ํ ์์
+ $entity = $this->getEntity($serverPartEntity->getPartUID());
+ if ($entity instanceof CSEntity) {
+ if ($entity->getStatus() !== STATUS['AVAILABLE']) {
+ throw new \Exception(__METHOD__ . ":์์ ์ค๋ฅ๋ฐ์: {$serverPartEntity->getTitle()}๋ ์ฌ์ฉ์ค์
๋๋ค.");
+ }
+ $entity = $this->model->modify($entity, $formDatas);
+ }
+ return $entity;
+ }
+ public function detachFromServerPart(ServerPartEntity $serverPartEntity): CSEntity
+ {
+ $formDatas = [];
+ $formDatas['clientinfo_uid'] = null;
+ $formDatas['serviceinfo_uid'] = null;
+ $formDatas['serverinfo_uid'] = null;
+ $formDatas['status'] = STATUS['AVAILABLE'];
+ if (!array_key_exists('status', $formDatas)) {
+ throw new \Exception(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์: CS์ํ๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.");
+ }
+ //CS์ ๋ณด๊ฐ์ ธ์ค๊ธฐ
+ $entity = $this->getEntity($serverPartEntity->getPartUID());
+ if (!$entity instanceof CSEntity) {
+ throw new \Exception("{$serverPartEntity->getPartUID()}์ ํด๋นํ๋ CS์ ๋ณด๋ฅผ ์ฐพ์์์์ต๋๋ค.");
+ }
+ //CS์ ๋ณด ์์
+ return $this->model->modify($entity, $formDatas);
+ }
}
diff --git a/app/Services/Part/DISKService.php b/app/Services/Part/DISKService.php
index dfb9032..07c4161 100644
--- a/app/Services/Part/DISKService.php
+++ b/app/Services/Part/DISKService.php
@@ -26,6 +26,10 @@ class DISKService extends PartService
{
return new DISKDTO($formDatas);
}
+ public function getEntityClass(): string
+ {
+ return DISKEntity::class;
+ }
public function getFormService(): DISKForm
{
if ($this->_form === null) {
@@ -97,7 +101,11 @@ class DISKService extends PartService
}
protected function create_process(array $formDatas): DISKEntity
{
- return new DISKEntity($formDatas);
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof DISKEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ DISKEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
protected function modify_process($uid, array $formDatas): DISKEntity
{
@@ -110,4 +118,10 @@ class DISKService extends PartService
//List ๊ฒ์์ฉ
//FormFilter ์กฐ๊ฑด์ ์ฒ๋ฆฌ
//๊ฒ์์ด์กฐ๊ฑด์ ์ฒ๋ฆฌ
+ //OrderBy ์ฒ๋ฆฌ
+ public function setOrderBy(mixed $field = null, mixed $value = null): void
+ {
+ $this->model->orderBy('title ASC');
+ parent::setOrderBy($field, $value);
+ }
}
diff --git a/app/Services/Part/IPService.php b/app/Services/Part/IPService.php
index 5bfc02a..efecc64 100644
--- a/app/Services/Part/IPService.php
+++ b/app/Services/Part/IPService.php
@@ -3,6 +3,8 @@
namespace App\Services\Part;
use App\DTOs\Part\IPDTO;
+use App\Entities\Equipment\ServerEntity;
+use App\Entities\Equipment\ServerPartEntity;
use App\Entities\Part\IPEntity;
use App\Forms\Part\IPForm;
use App\Helpers\Part\IPHelper;
@@ -26,6 +28,10 @@ class IPService extends PartService
{
return new IPDTO($formDatas);
}
+ public function getEntityClass(): string
+ {
+ return IPEntity::class;
+ }
public function getFormService(): IPForm
{
if ($this->_form === null) {
@@ -113,7 +119,11 @@ class IPService extends PartService
}
protected function create_process(array $formDatas): IPEntity
{
- return new IPEntity($formDatas);
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof IPEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ IPEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
protected function modify_process($uid, array $formDatas): IPEntity
{
@@ -132,4 +142,74 @@ class IPService extends PartService
$this->model->orderBy("INET_ATON(ip) ASC");
parent::setOrderBy($field, $value);
}
+
+ //์๋ฒ๊ด๋ จ ์์
+ public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): IPEntity
+ {
+ $formDatas = [];
+ $formDatas['clientinfo_uid'] = $serverEntity->getClientInfoUID();
+ $formDatas['serviceinfo_uid'] = $serverEntity->getServiceInfoUID();
+ $formDatas['serverinfo_uid'] = $serverEntity->getPK();
+ $formDatas['status'] = STATUS['OCCUPIED'];
+ //IP์ ๋ณด์์ ํด๋นํ๋ IP๊ฐ ์์ผ๋ฉด ๊ฐ์ ธ์์ ์ฌ์ฉ์ค์ธ์ง ์ฒดํฌ ํ ์์
+ $entity = $this->getEntity(['ip' => $serverEntity->getIP()]);
+ if (!$entity instanceof IPEntity) {
+ throw new \Exception("{$serverEntity->getIP()}์ ํด๋นํ๋ IP์ ๋ณด๋ฅผ ์ฐพ์์์์ต๋๋ค.");
+ }
+ if ($entity->getStatus() !== STATUS['AVAILABLE']) {
+ throw new \Exception(__METHOD__ . ":์์ ์ค๋ฅ๋ฐ์: {$serverEntity->getTitle()}๋ ์ฌ์ฉ์ค์
๋๋ค.");
+ }
+ return $this->model->modify($entity, $formDatas);
+ }
+ public function detachFromServer(ServerEntity $serverEntity): IPEntity
+ {
+ $formDatas = [];
+ $formDatas['clientinfo_uid'] = null;
+ $formDatas['serviceinfo_uid'] = null;
+ $formDatas['serverinfo_uid'] = null;
+ $formDatas['old_clientinfo_uid'] = $serverEntity->getClientInfoUID() ?? null;
+ $formDatas['status'] = STATUS['AVAILABLE'];
+ //IP์ ๋ณด๊ฐ์ ธ์ค๊ธฐ
+ $entity = $this->getEntity(['ip' => $serverEntity->getIP()]);
+ if (!$entity instanceof IPEntity) {
+ throw new \Exception("{$serverEntity->getIP()}์ ํด๋นํ๋ IP์ ๋ณด๋ฅผ ์ฐพ์์์์ต๋๋ค.");
+ }
+ //IP์ ๋ณด ์์
+ return $this->model->modify($entity, $formDatas);
+ }
+
+ //์๋ฒํํธ๊ด๋ จ ์์
+ public function attachToServerPart(ServerPartEntity $serverPartEntity): IPEntity
+ {
+ $formDatas = [];
+ $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID();
+ $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID();
+ $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID();
+ $formDatas['status'] = STATUS['OCCUPIED'];
+ //IP์ ๋ณด์์ ํด๋นํ๋ IP๊ฐ ์์ผ๋ฉด ๊ฐ์ ธ์์ ์ฌ์ฉ์ค์ธ์ง ์ฒดํฌ ํ ์์
+ $entity = $this->getEntity($serverPartEntity->getPartUID());
+ if ($entity instanceof IPEntity) {
+ if ($entity->getStatus() !== STATUS['AVAILABLE']) {
+ throw new \Exception(__METHOD__ . ":์์ ์ค๋ฅ๋ฐ์: {$entity->getTitle()}๋ ์ฌ์ฉ์ค์
๋๋ค.");
+ }
+ $entity = $this->model->modify($entity, $formDatas);
+ }
+ return $entity;
+ }
+ public function detachFromServerPart(ServerPartEntity $serverPartEntity): IPEntity
+ {
+ $formDatas = [];
+ $formDatas['clientinfo_uid'] = null;
+ $formDatas['serviceinfo_uid'] = null;
+ $formDatas['serverinfo_uid'] = null;
+ $formDatas['old_clientinfo_uid'] = $serverPartEntity->getClientInfoUID() ?? null;
+ $formDatas['status'] = STATUS['AVAILABLE'];
+ //IP์ ๋ณด๊ฐ์ ธ์ค๊ธฐ
+ $entity = $this->getEntity($serverPartEntity->getPartUID());
+ if (!$entity instanceof IPEntity) {
+ throw new \Exception("{$serverPartEntity->getPartUID()}์ ํด๋นํ๋ IP์ ๋ณด๋ฅผ ์ฐพ์์์์ต๋๋ค.");
+ }
+ //IP์ ๋ณด ์์
+ return $this->model->modify($entity, $formDatas);
+ }
}
diff --git a/app/Services/Part/PartService.php b/app/Services/Part/PartService.php
index 7ff7aa2..a2c3f35 100644
--- a/app/Services/Part/PartService.php
+++ b/app/Services/Part/PartService.php
@@ -2,6 +2,8 @@
namespace App\Services\Part;
+use App\Entities\Equipment\ServerPartEntity;
+use App\Entities\Part\PartEntity;
use App\Models\CommonModel;
use App\Services\CommonService;
@@ -12,4 +14,38 @@ abstract class PartService extends CommonService
parent::__construct($model);
$this->addClassPaths('Part');
}
+ public function getEntity(string|int|array $where, ?string $message = null): ?PartEntity
+ {
+ return parent::getEntity($where, $message);
+ }
+
+ //์๋ฒํํธ๊ด๋ จ ์์
+ public function attachToServerPart(ServerPartEntity $serverPartEntity): mixed
+ {
+ //๋ถํ์ ๋ณด๊ฐ์ ธ์ค๊ธฐ
+ $entity = $this->getEntity($serverPartEntity->getPartUID());
+ if (!$entity) {
+ throw new \Exception("{$serverPartEntity->getPartUID()}์ ํด๋นํ๋ ๋ถํ์ ๋ณด๋ฅผ ์ฐพ์์์์ต๋๋ค.");
+ }
+ //๋ถํ์ ๋ณด์ ์๋ฒ์ ๋ณด ์ค์ ๋ฐ ์๋น์ค,๊ณ ๊ฐ์ ๋ณด ์ ์
+ if ($entity->getAvailable() < $serverPartEntity->getCnt()) {
+ throw new \Exception("ํ์ฌ ์ฌ์ฉ๊ฐ๋ฅ ๊ฐฏ์[{$entity->getAvailable()}]๋ณด๋ค ์ง์ ํ์ ๊ฐฏ์({$serverPartEntity->getCnt()})๊ฐ ๋ ๋ง์ต๋๋ค.");
+ }
+ return $this->model->modify($entity, ['used' => $entity->getUsed() + $serverPartEntity->getCnt()]);
+ }
+ public function detachFromServerPart(ServerPartEntity $serverPartEntity): mixed
+ {
+ //๋ถํ์ ๋ณด๊ฐ์ ธ์ค๊ธฐ
+ $entity = $this->getEntity($serverPartEntity->getPartUID());
+ if (!$entity) {
+ throw new \Exception("{$serverPartEntity->getPartUID()}์ ํด๋นํ๋ ๋ถํ์ ๋ณด๋ฅผ ์ฐพ์์์์ต๋๋ค.");
+ }
+ //๋ถํ์ ๋ณด์ ์๋ฒ์ ๋ณด ์ค์ ๋ฐ ์๋น์ค,๊ณ ๊ฐ์ ๋ณด ์ ์
+ if ($entity->getUsed() < $serverPartEntity->getCnt()) {
+ throw new \Exception("ํ์ฌ ์ฌ์ฉ๋ ๊ฐฏ์[{$entity->getUsed()}]๋ณด๋ค ์ง์ ํ์ ๊ฐฏ์({$serverPartEntity->getCnt()})๊ฐ ๋ ๋ง์ต๋๋ค.");
+ }
+ $entity = $this->model->modify($entity, ['used' => $entity->getUsed() - $serverPartEntity->getCnt()]);
+ // dd($entity);
+ return $entity;
+ }
}
diff --git a/app/Services/Part/RAMService.php b/app/Services/Part/RAMService.php
index e5941a7..60f302c 100644
--- a/app/Services/Part/RAMService.php
+++ b/app/Services/Part/RAMService.php
@@ -26,6 +26,10 @@ class RAMService extends PartService
{
return new RAMDTO($formDatas);
}
+ public function getEntityClass(): string
+ {
+ return RAMEntity::class;
+ }
public function getFormService(): RAMForm
{
if ($this->_form === null) {
@@ -95,7 +99,11 @@ class RAMService extends PartService
}
protected function create_process(array $formDatas): RAMEntity
{
- return new RAMEntity($formDatas);
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof RAMEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ RAMEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
protected function modify_process($uid, array $formDatas): RAMEntity
{
@@ -108,4 +116,10 @@ class RAMService extends PartService
//List ๊ฒ์์ฉ
//FormFilter ์กฐ๊ฑด์ ์ฒ๋ฆฌ
//๊ฒ์์ด์กฐ๊ฑด์ ์ฒ๋ฆฌ
+ //OrderBy ์ฒ๋ฆฌ
+ public function setOrderBy(mixed $field = null, mixed $value = null): void
+ {
+ $this->model->orderBy('title ASC');
+ parent::setOrderBy($field, $value);
+ }
}
diff --git a/app/Services/Part/SOFTWAREService.php b/app/Services/Part/SOFTWAREService.php
index 0a34e0e..0ae832d 100644
--- a/app/Services/Part/SOFTWAREService.php
+++ b/app/Services/Part/SOFTWAREService.php
@@ -26,6 +26,10 @@ class SOFTWAREService extends PartService
{
return new SOFTWAREDTO($formDatas);
}
+ public function getEntityClass(): string
+ {
+ return SOFTWAREEntity::class;
+ }
public function getFormService(): SOFTWAREForm
{
if ($this->_form === null) {
@@ -95,7 +99,11 @@ class SOFTWAREService extends PartService
}
protected function create_process(array $formDatas): SOFTWAREEntity
{
- return new SOFTWAREEntity($formDatas);
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof SOFTWAREEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ SOFTWAREEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
protected function modify_process($uid, array $formDatas): SOFTWAREEntity
{
@@ -108,4 +116,10 @@ class SOFTWAREService extends PartService
//List ๊ฒ์์ฉ
//FormFilter ์กฐ๊ฑด์ ์ฒ๋ฆฌ
//๊ฒ์์ด์กฐ๊ฑด์ ์ฒ๋ฆฌ
+ //OrderBy ์ฒ๋ฆฌ
+ public function setOrderBy(mixed $field = null, mixed $value = null): void
+ {
+ $this->model->orderBy('title ASC');
+ parent::setOrderBy($field, $value);
+ }
}
diff --git a/app/Services/Part/SWITCHService.php b/app/Services/Part/SWITCHService.php
index a679606..c3a1dd8 100644
--- a/app/Services/Part/SWITCHService.php
+++ b/app/Services/Part/SWITCHService.php
@@ -3,6 +3,8 @@
namespace App\Services\Part;
use App\DTOs\Part\SWITCHDTO;
+use App\Entities\Equipment\ServerEntity;
+use App\Entities\Equipment\ServerPartEntity;
use App\Entities\Part\SWITCHEntity;
use App\Forms\Part\SWITCHForm;
use App\Helpers\Part\SWITCHHelper;
@@ -26,6 +28,10 @@ class SWITCHService extends PartService
{
return new SWITCHDTO($formDatas);
}
+ public function getEntityClass(): string
+ {
+ return SWITCHEntity::class;
+ }
public function getFormService(): SWITCHForm
{
if ($this->_form === null) {
@@ -114,7 +120,11 @@ class SWITCHService extends PartService
}
protected function create_process(array $formDatas): SWITCHEntity
{
- return new SWITCHEntity($formDatas);
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof SWITCHEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ SWITCHEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
protected function modify_process($uid, array $formDatas): SWITCHEntity
{
@@ -127,4 +137,91 @@ class SWITCHService extends PartService
//List ๊ฒ์์ฉ
//FormFilter ์กฐ๊ฑด์ ์ฒ๋ฆฌ
//๊ฒ์์ด์กฐ๊ฑด์ ์ฒ๋ฆฌ
+ //OrderBy ์ฒ๋ฆฌ
+ public function setOrderBy(mixed $field = null, mixed $value = null): void
+ {
+ $this->model->orderBy('code ASC');
+ parent::setOrderBy($field, $value);
+ }
+
+ //์๋ฒ๊ด๋ จ ์์
+ public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): SWITCHEntity
+ {
+ $formDatas = [];
+ $formDatas['clientinfo_uid'] = $serverEntity->getClientInfoUID();
+ $formDatas['serviceinfo_uid'] = $serverEntity->getServiceInfoUID();
+ $formDatas['serverinfo_uid'] = $serverEntity->getPK();
+ $formDatas['status'] = STATUS['OCCUPIED'];
+ if (!array_key_exists('status', $formDatas)) {
+ throw new \Exception(__METHOD__ . ":์์ ์ค๋ฅ๋ฐ์: Switch์ํ๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.");
+ }
+ //Switch์ ๋ณด์์ ํด๋นํ๋ IP๊ฐ ์์ผ๋ฉด ๊ฐ์ ธ์์ ์ฌ์ฉ์ค์ธ์ง ์ฒดํฌ ํ ์์
+ $entity = $this->getEntity($serverEntity->getSwitchInfoUID());
+ if (!$entity instanceof SWITCHEntity) {
+ throw new \Exception("{$serverEntity->getSwitchInfoUID()}์ ํด๋นํ๋ Switch์ ๋ณด๋ฅผ ์ฐพ์์์์ต๋๋ค.");
+ }
+ if ($entity->getStatus() !== STATUS['AVAILABLE']) {
+ throw new \Exception(__METHOD__ . ":์์ ์ค๋ฅ๋ฐ์: {$serverEntity->getTitle()}๋ ์ฌ์ฉ์ค์
๋๋ค.");
+ }
+ return $this->model->modify($entity, $formDatas);
+ }
+ public function detachFromServer(ServerEntity $serverEntity): SWITCHEntity
+ {
+ $formDatas = [];
+ $formDatas['clientinfo_uid'] = null;
+ $formDatas['serviceinfo_uid'] = null;
+ $formDatas['serverinfo_uid'] = null;
+ $formDatas['old_clientinfo_uid'] = $serverEntity->getClientInfoUID() ?? null;
+ $formDatas['status'] = STATUS['AVAILABLE'];
+ if (!array_key_exists('status', $formDatas)) {
+ throw new \Exception(__METHOD__ . ":์์ ์ค๋ฅ๋ฐ์: Switch์ํ๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.");
+ }
+ //Switch์ ๋ณด๊ฐ์ ธ์ค๊ธฐ
+ $entity = $this->getEntity($serverEntity->getSwitchInfoUID());
+ if (!$entity instanceof SWITCHEntity) {
+ throw new \Exception("{$serverEntity->getSwitchInfoUID()}์ ํด๋นํ๋ Switch์ ๋ณด๋ฅผ ์ฐพ์์์์ต๋๋ค.");
+ }
+ //Switch์ ๋ณด ์์
+ return $this->model->modify($entity, $formDatas);
+ }
+ //์๋ฒํํธ๊ด๋ จ ์์
+ public function attachToServerPart(ServerPartEntity $serverPartEntity): SWITCHEntity
+ {
+ $formDatas = [];
+ $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID();
+ $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID();
+ $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID();
+ $formDatas['status'] = STATUS['OCCUPIED'];
+ if (!array_key_exists('status', $formDatas)) {
+ throw new \Exception(__METHOD__ . ":์์ ์ค๋ฅ๋ฐ์: Switch์ํ๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.");
+ }
+ //SWITCH์ ๋ณด์์ ํด๋นํ๋ SWITCH๊ฐ ์์ผ๋ฉด ๊ฐ์ ธ์์ ์ฌ์ฉ์ค์ธ์ง ์ฒดํฌ ํ ์์
+ $entity = $this->getEntity($serverPartEntity->getPartUID());
+ if ($entity instanceof SWITCHEntity) {
+ if ($entity->getStatus() !== STATUS['AVAILABLE']) {
+ throw new \Exception(__METHOD__ . ":์์ ์ค๋ฅ๋ฐ์: {$entity->getTitle()}๋ ์ฌ์ฉ์ค์
๋๋ค.");
+ }
+ $entity = $this->model->modify($entity, $formDatas);
+ }
+ return $entity;
+ }
+ public function detachFromServerPart(ServerPartEntity $serverPartEntity): SWITCHEntity
+ {
+ $formDatas = [];
+ $formDatas['clientinfo_uid'] = null;
+ $formDatas['serviceinfo_uid'] = null;
+ $formDatas['serverinfo_uid'] = null;
+ $formDatas['old_clientinfo_uid'] = $serverPartEntity->getClientInfoUID() ?? null;
+ $formDatas['status'] = STATUS['AVAILABLE'];
+ if (!array_key_exists('status', $formDatas)) {
+ throw new \Exception(__METHOD__ . ":์์ ์ค๋ฅ๋ฐ์: Switch์ํ๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.");
+ }
+ //Switch์ ๋ณด๊ฐ์ ธ์์ ์์ผ๋ฉด ์์
+ $entity = $this->getEntity($serverPartEntity->getPartUID());
+ if (!$entity instanceof SWITCHEntity) {
+ throw new \Exception("{$serverPartEntity->getPartUID()}์ ํด๋นํ๋ Switch์ ๋ณด๋ฅผ ์ฐพ์์์์ต๋๋ค.");
+ }
+ //Switch์ ๋ณด ์์
+ return $this->model->modify($entity, $formDatas);
+ }
}
diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php
index 28644f2..7558d35 100644
--- a/app/Services/PaymentService.php
+++ b/app/Services/PaymentService.php
@@ -25,6 +25,10 @@ class PaymentService extends CommonService
{
return PaymentDTO::class;
}
+ public function getEntityClass(): string
+ {
+ return PaymentEntity::class;
+ }
public function createDTO(array $formDatas): PaymentDTO
{
return new PaymentDTO($formDatas);
@@ -130,11 +134,19 @@ class PaymentService extends CommonService
}
protected function create_process(array $formDatas): PaymentEntity
{
- return new PaymentEntity($formDatas);
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof PaymentEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ PaymentEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
protected function modify_process($uid, array $formDatas): PaymentEntity
{
- return parent::modify_process($uid, $formDatas);
+ $entity = parent::modify_process($uid, $formDatas);
+ if (!$entity instanceof PaymentEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ PaymentEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
//List ๊ฒ์์ฉ
//FormFilter ์กฐ๊ฑด์ ์ฒ๋ฆฌ
diff --git a/app/Services/UserService.php b/app/Services/UserService.php
index 81361c2..d4ba41e 100644
--- a/app/Services/UserService.php
+++ b/app/Services/UserService.php
@@ -26,6 +26,10 @@ class UserService extends CommonService
{
return new UserDTO($formDatas);
}
+ public function getEntityClass(): string
+ {
+ return UserEntity::class;
+ }
public function getFormService(): UserForm
{
if ($this->_form === null) {
@@ -102,7 +106,11 @@ class UserService extends CommonService
if (isset($formDatas['confirmpassword'])) {
unset($formDatas['confirmpassword']);
}
- return new UserEntity($formDatas);
+ $entity = parent::create_process($formDatas);
+ if (!$entity instanceof UserEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ UserEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
protected function modify_process($uid, array $formDatas): UserEntity
{
@@ -110,7 +118,11 @@ class UserService extends CommonService
if (isset($formDatas['confirmpassword'])) {
unset($formDatas['confirmpassword']);
}
- return parent::modify_process($uid, $formDatas);
+ $entity = parent::modify_process($uid, $formDatas);
+ if (!$entity instanceof UserEntity) {
+ throw new RuntimeException(__METHOD__ . "์์ ์ค๋ฅ๋ฐ์:Return Type์ UserEntity๋ง ๊ฐ๋ฅ");
+ }
+ return $entity;
}
//List ๊ฒ์์ฉ
//FormFilter ์กฐ๊ฑด์ ์ฒ๋ฆฌ