diff --git a/app/Controllers/Admin/Home.php b/app/Controllers/Admin/Home.php index 6ea3a3e..b899d0b 100644 --- a/app/Controllers/Admin/Home.php +++ b/app/Controllers/Admin/Home.php @@ -19,7 +19,7 @@ class Home extends AdminController } protected function getServiceClass(): Service { - if ($this->service === null) { + if (!$this->service) { $this->service = new Service($this->request); } return $this->service; diff --git a/app/Controllers/Admin/MyLogController.php b/app/Controllers/Admin/MyLogController.php index 3700c7d..938250a 100644 --- a/app/Controllers/Admin/MyLogController.php +++ b/app/Controllers/Admin/MyLogController.php @@ -22,14 +22,14 @@ class MyLogController extends AdminController } protected function getServiceClass(): Service { - if ($this->service === null) { + if (!$this->service) { $this->service = new Service(); } return $this->service; } public function getUserService(): UserService { - if ($this->_userService === null) { + if (!$this->_userService) { $this->_userService = new UserService($this->request); } return $this->_userService; diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index 571e77b..6c53126 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -22,7 +22,7 @@ class UserController extends AdminController } protected function getServiceClass(): Service { - if ($this->service === null) { + if (!$this->service) { $this->service = new Service($this->request); } return $this->service; @@ -40,7 +40,7 @@ class UserController extends AdminController { return ['status']; } - protected function setValidation(string $action, string $field, string $rule, Validation $validation): Validation + protected function setValidation(Validation $validation, string $action, string $field, ?string $rule = null): Validation { switch ($field) { case 'role': @@ -48,7 +48,7 @@ class UserController extends AdminController $validation->setRule("{$field}.*", $field, $rule); break; default: - $validation = parent::setValidation($action, $field, $rule, $validation); + $validation = parent::setValidation($validation, $action, $field, $rule); break; } return $validation; diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index e5ae436..12b3112 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -43,7 +43,7 @@ abstract class CommonController extends BaseController } final public function getService(): mixed { - if ($this->_service === null) { + if (!$this->_service) { $serviceClass = $this->getServiceClass(); $this->_service = new $serviceClass($this->request); // $this->_service->setDebug(true); @@ -111,11 +111,11 @@ abstract class CommonController extends BaseController // dd($options); return $options; } - protected function setValidation(string $action, string $field, string $rule, Validation $validation): Validation + protected function setValidation(Validation $validation, string $action, string $field, ?string $rule = null): Validation { switch ($field) { default: - $validation->setRule($field, $field, $this->getService()->getModel()->getFieldRule($action, $field)); + $validation->setRule($field, $field, $rule ?? $this->getService()->getModel()->getFieldRule($action, $field)); break; } return $validation; @@ -139,8 +139,8 @@ abstract class CommonController extends BaseController $validation = service('validation'); // var_dump($this->field_rules); // exit; - foreach ($this->field_rules as $field => $rule) { - $validation = $this->setValidation($this->action, $field, $rule, $validation); + foreach ($fields as $field) { + $validation = $this->setValidation($validation, $this->action, $field, $this->field_rules[$field] ?? null); } if (!$validation->withRequest($this->request)->run()) { throw new \Exception("{$this->getService()->getClassName()} 작업 데이터 검증 오류발생\n" . implode( @@ -193,7 +193,7 @@ abstract class CommonController extends BaseController { $this->getService()->getModel()->where($this->getService()->getModel()::PK, $uid); $entity = $this->getService()->getEntity(); - if ($entity === null) { + if (!$entity) { throw new \Exception("해당 정보를 찾을수 없습니다."); } return $entity; @@ -329,10 +329,10 @@ abstract class CommonController extends BaseController $this->init(__FUNCTION__); $this->getService()->getModel()->where($this->getService()->getModel()::PK, $uid); $entity = $this->getService()->getEntity(); - if ($entity === null) { + if (!$entity) { throw new \Exception("{$uid} 정보를 찾을수 없습니다."); } - $this->entity = $this->delete_process($uid); + $this->entity = $this->delete_process($entity); $this->getService()->getModel()->transCommit(); return $this->getResultPageByActon($this->action); } catch (\Exception $e) { @@ -356,10 +356,10 @@ abstract class CommonController extends BaseController foreach ($entities as $entity) { try { if ($this->getService()->delete($entity)) { - MyLogService::debug("[$entity->getTitle()]" . MESSAGES["DELETED"]); + MyLogService::debug("[{$entity->getTitle()}]" . MESSAGES["DELETED"]); } } catch (PDOException $e) { - MyLogService::debug("[$entity->getTitle()]" . MESSAGES["FAILED"] . ":" . $e->getMessage()); + MyLogService::debug("[{$entity->getTitle()}]" . MESSAGES["FAILED"] . ":" . $e->getMessage()); } } } @@ -550,7 +550,7 @@ abstract class CommonController extends BaseController } $this->getService()->getModel()->where($this->getService()->getModel()::PK, $uid); $this->entity = $this->getService()->getEntity(); - if ($this->entity === null) { + if (!$this->entity) { throw new \Exception("{$uid} 정보를 찾을수 없습니다."); } list($file_name, $uploaded_filename) = $this->entity->getDownlaodFile(); diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index 4ea21f5..a14d9a4 100644 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -26,7 +26,7 @@ class UserController extends CommonController } protected function getServiceClass(): Service { - if ($this->service === null) { + if (!$this->service) { $this->service = new Service($this->request); } return $this->service; diff --git a/app/Entities/CommonEntity.php b/app/Entities/CommonEntity.php index 1e79924..32e53de 100644 --- a/app/Entities/CommonEntity.php +++ b/app/Entities/CommonEntity.php @@ -16,8 +16,6 @@ abstract class CommonEntity extends Entity { parent::__construct($data); } - - abstract public function __toString(); final public function getPK(): string { $field = constant("static::PK"); @@ -30,7 +28,7 @@ abstract class CommonEntity extends Entity } final public function getUpdatedAt(): string { - return $this->created_at; + return $this->updated_at; } final public function getCreatedAt(): string { diff --git a/app/Entities/MyLogEntity.php b/app/Entities/MyLogEntity.php index 57dc7ab..58d859b 100644 --- a/app/Entities/MyLogEntity.php +++ b/app/Entities/MyLogEntity.php @@ -2,17 +2,13 @@ namespace App\Entities; -use App\Entities\CommonEntity as Entity; +use App\Entities\CommonEntity; use App\Models\MyLogModel as Model; -class MyLogEntity extends Entity +class MyLogEntity extends CommonEntity { const PK = Model::PK; const TITLE = Model::TITLE; - public function __toString(): string - { - return "{$this->getPK()}:{$this->getTitle()}}"; - } //공통부분 //Common Function } diff --git a/app/Entities/UserEntity.php b/app/Entities/UserEntity.php index dbf8d2d..0933325 100644 --- a/app/Entities/UserEntity.php +++ b/app/Entities/UserEntity.php @@ -2,19 +2,13 @@ namespace App\Entities; -use App\Entities\CommonEntity as Entity; +use App\Entities\CommonEntity; use App\Models\UserModel as Model; class UserEntity extends CommonEntity { const PK = Model::PK; const TITLE = Model::TITLE; - public function __toString(): string - { - return "{$this->getPK()}:{$this->getID()}:{$this->getTitle()},{$this->getRole()}}"; - } - //공통부분 - public function getID(): string { return $this->attributes['id']; diff --git a/app/Entities/UserSNSEntity.php b/app/Entities/UserSNSEntity.php index 38a81dc..48b84e9 100644 --- a/app/Entities/UserSNSEntity.php +++ b/app/Entities/UserSNSEntity.php @@ -9,10 +9,6 @@ class UserSNSEntity extends CommonEntity { const PK = Model::PK; const TITLE = Model::TITLE; - public function __toString(): string - { - return "{$this->getPK()}|{$this->getID()}|{$this->getTitle()}"; - } //Common Function public function getParent(): int|null { diff --git a/app/Libraries/MySocket/GoogleSocket/API.php b/app/Libraries/MySocket/GoogleSocket/API.php index 414562a..29c5b7e 100644 --- a/app/Libraries/MySocket/GoogleSocket/API.php +++ b/app/Libraries/MySocket/GoogleSocket/API.php @@ -16,7 +16,7 @@ class API extends GoogleSocket public function getClient(): Client { - if ($this->_client === null) { + if (!$this->_client) { $this->_client = new Client(); $this->_client->setClientId(env('socket.google.client.id')); $this->_client->setClientSecret(env('socket.google.client.key')); diff --git a/app/Libraries/MySocket/GoogleSocket/CURL.php b/app/Libraries/MySocket/GoogleSocket/CURL.php index 3b966e8..7e1eb90 100644 --- a/app/Libraries/MySocket/GoogleSocket/CURL.php +++ b/app/Libraries/MySocket/GoogleSocket/CURL.php @@ -14,7 +14,7 @@ class CURL extends GoogleSocket public function getClient(): Client { - if ($this->_client === null) { + if (!$this->_client) { $this->_client = new Client(); } return $this->_client; diff --git a/app/Libraries/MySocket/GoogleSocket/GoogleSocket.php b/app/Libraries/MySocket/GoogleSocket/GoogleSocket.php index 9201a3e..cd3a285 100644 --- a/app/Libraries/MySocket/GoogleSocket/GoogleSocket.php +++ b/app/Libraries/MySocket/GoogleSocket/GoogleSocket.php @@ -39,7 +39,7 @@ abstract class GoogleSocket extends MySocket } public function getService(): Service { - if ($this->_service === null) { + if (!$this->_service) { $this->_service = new Service(); } return $this->_service; @@ -49,7 +49,7 @@ abstract class GoogleSocket extends MySocket $this->getService()->getModel()->where(Model::SITE, $this->getSite()); $this->getService()->getModel()->where('id', $id); $entity = $this->getEntity(); - if ($entity === null) { + if (!$entity) { //Transaction Start $this->getService()->getModel()->transStart(); try { diff --git a/app/Libraries/MySocket/MySocket.php b/app/Libraries/MySocket/MySocket.php index da66c0f..8714f52 100644 --- a/app/Libraries/MySocket/MySocket.php +++ b/app/Libraries/MySocket/MySocket.php @@ -14,7 +14,7 @@ abstract class MySocket abstract public function getClient(): mixed; final protected function getCookieJar(): CookieJar { - if ($this->_cookieJar === null) { + if (!$this->_cookieJar) { $this->_cookieJar = new CookieJar(); } return $this->_cookieJar; diff --git a/app/Libraries/MySocket/WebSocket.php b/app/Libraries/MySocket/WebSocket.php index fbe94ad..79fb22e 100644 --- a/app/Libraries/MySocket/WebSocket.php +++ b/app/Libraries/MySocket/WebSocket.php @@ -16,7 +16,7 @@ class WebSocket extends MySocket } public function getClient(): Client { - if ($this->_client === null) { + if (!$this->_client) { $this->_client = new Client(); } return $this->_client; diff --git a/app/Models/CommonModel.php b/app/Models/CommonModel.php index c0859b9..fe3c933 100644 --- a/app/Models/CommonModel.php +++ b/app/Models/CommonModel.php @@ -142,7 +142,7 @@ abstract class CommonModel extends Model if (!$entity->hasChanged()) { throw new \Exception(__FUNCTION__ . " 변경된 내용이 없습니다."); } - // log_message("debug", var_export($entity, true)); + log_message("debug", var_export($entity, true)); // 최종 저장 시 오류 발생하면 if (!$this->save($entity)) { throw new \Exception("저장오류:" . var_export($this->errors(), true)); diff --git a/app/Services/Auth/AuthService.php b/app/Services/Auth/AuthService.php index 73b37d6..0534a09 100644 --- a/app/Services/Auth/AuthService.php +++ b/app/Services/Auth/AuthService.php @@ -11,12 +11,10 @@ use CodeIgniter\Session\Session; abstract class AuthService extends CommonService { private ?Session $_session = null; - private ?Model $_model = null; - public function __construct() {} final public function getSession(): Session { - if ($this->_session === null) { + if (!$this->_session) { $this->_session = \Config\Services::session(); } return $this->_session; @@ -41,7 +39,6 @@ abstract class AuthService extends CommonService return $this->getAuthInfo('id'); } - final public function getNameByAuthInfo(): string { return $this->getAuthInfo('name'); @@ -52,7 +49,6 @@ abstract class AuthService extends CommonService return $this->getAuthInfo('role'); } - final public function isLoggedIn(): bool { return $this->getSession()->has(SESSION_NAMES['ISLOGIN']); diff --git a/app/Services/Auth/GoogleService.php b/app/Services/Auth/GoogleService.php index 0ebd757..02c3620 100644 --- a/app/Services/Auth/GoogleService.php +++ b/app/Services/Auth/GoogleService.php @@ -36,7 +36,7 @@ class GoogleService extends AuthService public function getMySocket(string $access_code): mixed { - if ($this->_mySocket === null) { + if (!$this->_mySocket) { throw new \Exception("Socket 방식이 지정되지 않았습니다."); } $this->_mySocket->setToken($this->_access_code); @@ -51,7 +51,7 @@ class GoogleService extends AuthService // local db 사용와의 연결 확인 $this->getModel()->where($this->getModel()::PK, $userSNS_entity->getParent()); $entity = $this->getEntity(); - if ($entity === null) { + if (!$entity) { throw new PageNotFoundException("회원[{$userSNS_entity->getTitle()}]님은 아직 로컬사용자 연결이 이루어지지 않았습니다."); } return $entity; diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index 3441e13..ff9b076 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -33,7 +33,7 @@ abstract class CommonService } final public function getModel(): mixed { - if ($this->_model === null) { + if (!$this->_model) { $modelClass = $this->getModelClass(); $this->_model = new $modelClass(); // $this->_model->setDebug(true); diff --git a/app/Services/MyLogService.php b/app/Services/MyLogService.php index a99b6ce..fc3e0be 100644 --- a/app/Services/MyLogService.php +++ b/app/Services/MyLogService.php @@ -13,7 +13,7 @@ class MyLogService public function __construct() {} static public function getModel(): Model { - if (self::$_model === null) { + if (!self::$_model) { self::$_model = new Model(); } return self::$_model; diff --git a/app/Services/UserService.php b/app/Services/UserService.php index 7b0c154..f9ff582 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -61,6 +61,6 @@ class UserService extends CommonService } public function delete(Entity $entity): bool { - return $this->getModel()->delete($entity->getPK()); + return $this->getModel()->delete($entity); } }