servermgrv2 init...

This commit is contained in:
최준흠git config git config --helpgit config --global user.name 최준흠 2023-07-23 10:31:52 +09:00
parent b3659ee820
commit 69e9ac9295
19 changed files with 286 additions and 265 deletions

View File

@ -182,7 +182,7 @@ foreach (PATHS as $key => $path) {
//아이콘 및 Sound관련 //아이콘 및 Sound관련
define('ICONS', [ define('ICONS', [
'NEW' => '<i class="fa fa-paper-plane" aria-hidden="true"></i>', 'NEW' => '<i class="fa fa-paper-plane" aria-hidden="true"></i>',
'REPLY' => '<button style="font-size:12px"><i class="fa fa-reply"></i>Reply</button>', 'REPLY' => '<i class="fa fa-reply"></i>',
'DELETE' => '<i class="fa fa-trash-o"></i>', 'DELETE' => '<i class="fa fa-trash-o"></i>',
'RELOAD' => '<i class="fa fa-refresh" aria-hidden="true"></i>', 'RELOAD' => '<i class="fa fa-refresh" aria-hidden="true"></i>',
'SETTING' => '<i class="fa fa-cogs" aria-hidden="true"></i>', 'SETTING' => '<i class="fa fa-cogs" aria-hidden="true"></i>',
@ -199,6 +199,7 @@ define('DEFAULTS', [
'STATUS' => getenv('default.status') ?: "use", 'STATUS' => getenv('default.status') ?: "use",
'EMPTY' => getenv('default.empty') ?: "", 'EMPTY' => getenv('default.empty') ?: "",
'PERPAGE' => getenv('default.perpage') ?: 20, 'PERPAGE' => getenv('default.perpage') ?: 20,
'HIERARCHY_GRPDEPTH' => getenv('default. hierarchy_grpdepth') ?: 20,
]); ]);
//API Adapter초기갑 정의 //API Adapter초기갑 정의

View File

@ -8,6 +8,7 @@ use CodeIgniter\Filters\DebugToolbar;
use CodeIgniter\Filters\Honeypot; use CodeIgniter\Filters\Honeypot;
use CodeIgniter\Filters\InvalidChars; use CodeIgniter\Filters\InvalidChars;
use CodeIgniter\Filters\SecureHeaders; use CodeIgniter\Filters\SecureHeaders;
use App\Filters\AuthFilter;
class Filters extends BaseConfig class Filters extends BaseConfig
{ {
@ -21,7 +22,7 @@ class Filters extends BaseConfig
'honeypot' => Honeypot::class, 'honeypot' => Honeypot::class,
'invalidchars' => InvalidChars::class, 'invalidchars' => InvalidChars::class,
'secureheaders' => SecureHeaders::class, 'secureheaders' => SecureHeaders::class,
'authFilter' => \App\Filters\AuthFilter::class, 'authFilter' => AuthFilter::class,
]; ];
/** /**

View File

@ -50,55 +50,55 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
$routes->group('user', static function ($routes) { $routes->group('user', static function ($routes) {
$routes->get('', 'UserController::index'); $routes->get('', 'UserController::index');
$routes->get('excel', 'UserController::excel'); $routes->get('excel', 'UserController::excel');
$routes->get('insert', 'UserController::insert_form', ['filter' => 'authFilter:master,director']); $routes->get('insert', 'UserController::insert_form');
$routes->post('insert', 'UserController::insert', ['filter' => 'authFilter:master,director']); $routes->post('insert', 'UserController::insert');
$routes->get('update/(:uuid)', 'UserController::update_form/$1'); $routes->get('update/(:uuid)', 'UserController::update_form/$1');
$routes->post('update/(:uuid)', 'UserController::update/$1'); $routes->post('update/(:uuid)', 'UserController::update/$1');
$routes->get('view/(:uuid)', 'UserController::view/$1'); $routes->get('view/(:uuid)', 'UserController::view/$1');
$routes->get('delete/(:uuid)', 'UserController::delete/$1', ['filter' => 'authFilter:master,director']); $routes->get('delete/(:uuid)', 'UserController::delete/$1', ['filter' => 'authFilter:master']);
$routes->get('toggle/(:uuid)/(:hash)', 'UserController::toggle/$1/$2', ['filter' => 'authFilter:master,director']); $routes->get('toggle/(:uuid)/(:hash)', 'UserController::toggle/$1/$2');
$routes->post('batchjob', 'UserController::batchjob', ['filter' => 'authFilter:master,director']); $routes->post('batchjob', 'UserController::batchjob');
}); });
$routes->group('usersns', static function ($routes) { $routes->group('usersns', static function ($routes) {
$routes->get('', 'UserSNSController::index'); $routes->get('', 'UserSNSController::index');
$routes->get('excel', 'UserSNSController::excel'); $routes->get('excel', 'UserSNSController::excel');
$routes->get('view/(:num)', 'UserSNSController::view/$1'); $routes->get('view/(:num)', 'UserSNSController::view/$1');
$routes->get('delete/(:num)', 'UserSNSController::delete/$1', ['filter' => 'authFilter:master,director']); $routes->get('delete/(:num)', 'UserSNSController::delete/$1');
$routes->get('toggle/(:num)/(:hash)', 'UserSNSController::toggle/$1/$2', ['filter' => 'authFilter:master,director']); $routes->get('toggle/(:num)/(:hash)', 'UserSNSController::toggle/$1/$2');
}); });
$routes->group('logger', static function ($routes) { $routes->group('logger', ['filter' => 'authFilter:master,director,cloudflare,manager'], static function ($routes) {
$routes->get('', 'LoggerController::index'); $routes->get('', 'LoggerController::index');
$routes->get('excel', 'LoggerController::excel'); $routes->get('excel', 'LoggerController::excel');
$routes->get('view/(:num)', 'LoggerController::view/$1'); $routes->get('view/(:num)', 'LoggerController::view/$1');
$routes->get('delete/(:num)', 'LoggerController::delete/$1', ['filter' => 'authFilter:master']); $routes->get('delete/(:num)', 'LoggerController::delete/$1', ['filter' => 'authFilter:master']);
$routes->get('toggle/(:num)/(:hash)', 'LoggerController::toggle/$1/$2', ['filter' => 'authFilter:master,director']); $routes->get('toggle/(:num)/(:hash)', 'LoggerController::toggle/$1/$2');
$routes->post('batchjob', 'LoggerController::batchjob', ['filter' => 'authFilter:master']); $routes->post('batchjob', 'LoggerController::batchjob');
}); });
$routes->group('boardconfig', static function ($routes) { $routes->group('boardconfig', static function ($routes) {
$routes->get('', 'BoardConfigController::index'); $routes->get('', 'BoardConfigController::index');
$routes->get('excel', 'BoardConfigController::excel/$1'); $routes->get('excel', 'BoardConfigController::excel/$1');
$routes->get('insert', 'BoardConfigController::insert_form', ['filter' => 'authFilter:master,director']); $routes->get('insert', 'BoardConfigController::insert_form');
$routes->post('insert', 'BoardConfigController::insert', ['filter' => 'authFilter:master,director']); $routes->post('insert', 'BoardConfigController::insert');
$routes->get('update/(:uuid)', 'BoardConfigController::update_form/$1'); $routes->get('update/(:uuid)', 'BoardConfigController::update_form/$1');
$routes->post('update/(:uuid)', 'BoardConfigController::update/$1'); $routes->post('update/(:uuid)', 'BoardConfigController::update/$1');
$routes->get('view/(:uuid)', 'BoardConfigController::view/$1'); $routes->get('view/(:uuid)', 'BoardConfigController::view/$1');
$routes->get('delete/(:uuid)', 'BoardConfigController::delete/$1', ['filter' => 'authFilter:master,director']); $routes->get('delete/(:uuid)', 'BoardConfigController::delete/$1', ['filter' => 'authFilter:master']);
$routes->get('toggle/(:uuid)/(:hash)', 'BoardConfigController::toggle/$1/$2', ['filter' => 'authFilter:master,director']); $routes->get('toggle/(:uuid)/(:hash)', 'BoardConfigController::toggle/$1/$2');
$routes->post('batchjob', 'BoardConfigController::batchjob', ['filter' => 'authFilter:master,director']); $routes->post('batchjob', 'BoardConfigController::batchjob');
}); });
$routes->group('board', static function ($routes) { $routes->group('board', static function ($routes) {
$routes->get('', 'BoardController::index'); $routes->get('', 'BoardController::index');
$routes->get('excel', 'BoardController::excel/$1'); $routes->get('excel', 'BoardController::excel/$1');
$routes->get('insert', 'BoardController::insert_form', ['filter' => 'authFilter:master,director']); $routes->get('insert', 'BoardController::insert_form');
$routes->post('insert', 'BoardController::insert', ['filter' => 'authFilter:master,director']); $routes->post('insert', 'BoardController::insert');
$routes->get('update/(:num)', 'BoardController::update_form/$1'); $routes->get('update/(:num)', 'BoardController::update_form/$1');
$routes->post('update/(:num)', 'BoardController::update/$1'); $routes->post('update/(:num)', 'BoardController::update/$1');
$routes->get('view/(:num)', 'BoardController::view/$1'); $routes->get('view/(:num)', 'BoardController::view/$1');
$routes->get('reply/(:num)', 'BoardController::reply_form/$1'); $routes->get('reply/(:num)', 'BoardController::reply_form/$1');
$routes->post('reply/(:num)', 'BoardController::reply/$1'); $routes->post('reply/(:num)', 'BoardController::reply/$1');
$routes->get('delete/(:num)', 'BoardController::delete/$1', ['filter' => 'authFilter:master,director']); $routes->get('delete/(:num)', 'BoardController::delete/$1', ['filter' => 'authFilter:master']);
$routes->get('toggle/(:num)/(:hash)', 'BoardController::toggle/$1/$2', ['filter' => 'authFilter:master,director']); $routes->get('toggle/(:num)/(:hash)', 'BoardController::toggle/$1/$2');
$routes->post('batchjob', 'BoardController::batchjob', ['filter' => 'authFilter:master,director']); $routes->post('batchjob', 'BoardController::batchjob');
}); });
}); });
/* /*

View File

@ -78,15 +78,13 @@ class BoardController extends \App\Controllers\Admin\AdminController
{ {
switch ($field) { switch ($field) {
case 'board_config_uid': case 'board_config_uid':
if (is_null($this->_board_config_uids)) { $options = $this->_board_config_uids = $this->_board_config_uids ?: $this->getBoardConfigModel()->getFieldFormOptions(['status' => 'use']);
//모든 필요한 FormOption등 조기화작업 필요 break;
$this->_board_config_uids = $this->getBoardConfigModel()->getFieldFormOptions(['status' => 'use']);
}
return $this->_board_config_uids;
default: default:
return parent::getFieldFormOption($field); $options = parent::getFieldFormOption($field);
break; break;
} }
return $options;
} }
//Field별 Form Datas 처리용 //Field별 Form Datas 처리용
@ -104,9 +102,8 @@ class BoardController extends \App\Controllers\Admin\AdminController
////Action 모음 ////Action 모음
//Insert관련 //Insert관련
protected function insert_process() final protected function insert_process()
{ {
// upload처리
return parent::insert_process(); return parent::insert_process();
} }
final public function insert() final public function insert()
@ -119,7 +116,7 @@ class BoardController extends \App\Controllers\Admin\AdminController
return $this->update_procedure($uid); return $this->update_procedure($uid);
} }
//Reply 관련 //Reply 관련
final public function reply(int $uid) final public function reply($uid)
{ {
return $this->reply_procedure($uid); return $this->reply_procedure($uid);
} }

View File

@ -51,20 +51,20 @@ class LoggerController extends \App\Controllers\Admin\AdminController
////Action 모음 ////Action 모음
//Insert관련 //Insert관련
final public function insert() // final public function insert()
{ // {
return $this->insert_procedure(); // return $this->insert_procedure();
} // }
//Update관련 //Update관련
final public function update($uid) // final public function update($uid)
{ // {
return $this->update_procedure($uid); // return $this->update_procedure($uid);
} // }
//Toggle관련 // //Toggle관련
final public function toggle($uid, string $field) // final public function toggle($uid, string $field)
{ // {
return $this->toggle_procedure($uid, $field); // return $this->toggle_procedure($uid, $field);
} // }
//Batchjob 관련 //Batchjob 관련
// final public function batchjob() // final public function batchjob()
// { // {

View File

@ -88,20 +88,16 @@ abstract class BaseController extends Controller
{ {
switch ($field) { switch ($field) {
case 'user_uid': case 'user_uid':
if (is_null($this->_user_uids)) { $options = $this->_user_uids = $this->_user_uids ?: $this->getUserModel()->getFieldFormOptions(['status' => 'use']);
//모든 필요한 FormOption등 조기화작업 필요
$this->_user_uids = $this->getUserModel()->getFieldFormOptions(['status' => 'use']);
}
return $this->_user_uids;
break; break;
default: default:
$formOptionDatas = lang($this->_className . '.' . strtoupper($field)); $options = lang($this->_className . '.' . strtoupper($field));
if (!is_array($formOptionDatas)) {
throw new \Exception("{$this->_className}에서 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($formOptionDatas, true));
}
return $formOptionDatas;
break; break;
} }
if (!is_array($options)) {
throw new \Exception(__FUNCTION__ . "에서 {$this->_className}의 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($options, true));
}
return $options;
} }
//Field별 Form Option용 //Field별 Form Option용
final protected function getFieldFormOptions(array $fields): array final protected function getFieldFormOptions(array $fields): array
@ -121,7 +117,7 @@ abstract class BaseController extends Controller
$tempRules = $this->_model->getValidationRules(['only' => $fields]); $tempRules = $this->_model->getValidationRules(['only' => $fields]);
foreach ($fields as $field) { foreach ($fields as $field) {
if (!is_string($field)) { if (!is_string($field)) {
throw new \Exception(__FUNCTION__ . "에서 {$field}가 string 아닙니다.\n" . var_export($fieldRules, true)); throw new \Exception(__FUNCTION__ . "에서 {$this->_className}의 Field:{$field}가 string 아닙니다.\n" . var_export($fieldRules, true));
} }
if (array_key_exists($field, $fieldRules)) { if (array_key_exists($field, $fieldRules)) {
$tempRules[$field] = $fieldRules[$field]; $tempRules[$field] = $fieldRules[$field];
@ -332,7 +328,7 @@ abstract class BaseController extends Controller
} }
protected function reply_form_process($entity) protected function reply_form_process($entity)
{ {
return $entity; return $this->update_form_process($entity);
} }
final public function reply_form($uid) final public function reply_form($uid)
{ {
@ -340,7 +336,7 @@ abstract class BaseController extends Controller
$entity = $this->_model->getEntity($uid); $entity = $this->_model->getEntity($uid);
$this->reply_init(); $this->reply_init();
$this->reply_form_init(); $this->reply_form_init();
$this->_viewDatas['entity'] = $this->update_form_process($entity); $this->_viewDatas['entity'] = $this->reply_form_process($entity);
return view($this->_viewPath . '/reply', $this->_viewDatas); return view($this->_viewPath . '/reply', $this->_viewDatas);
} catch (\Exception $e) { } catch (\Exception $e) {
return alert_CommonHelper($e->getMessage(), 'back'); return alert_CommonHelper($e->getMessage(), 'back');

View File

@ -107,7 +107,7 @@ function getFieldIndex_Row_BoardConfigHelper($field, array $row, array $fieldFil
{ {
switch ($field) { switch ($field) {
case 'name': case 'name':
return anchor(current_url() . '/view/' . $row['uid'], $row[$field], ["target" => "_self"]); return anchor(current_url() . '/view/' . $row['uid'], $row[$field], [...$attributes, "target" => "_self"]);
break; break;
case 'isaccess': case 'isaccess':
case 'isread': case 'isread':

View File

@ -81,9 +81,9 @@ function getFieldIndex_Row_BoardHelper($field, array $row, array $fieldFilters,
case 'title': case 'title':
return sprintf( return sprintf(
'<div style="text-align:left; padding-left:%spx;">%s&nbsp;&nbsp;%s</div>', '<div style="text-align:left; padding-left:%spx;">%s&nbsp;&nbsp;%s</div>',
$row['grpdepth'] * 30, $row['grpdepth'] * DEFAULTS['HIERARCHY_GRPDEPTH'],
anchor(current_url() . '/view/' . $row['uid'], $row[$field], ["target" => "_self"]), anchor(current_url() . '/view/' . $row['uid'], $row[$field], [...$attributes, "target" => "_self"]),
anchor(current_url() . '/reply/' . $row['uid'], ICONS['REPLY'], ["target" => "_self"]) anchor(current_url() . '/reply/' . $row['uid'], ICONS['REPLY'], [...$attributes, "target" => "_self"])
); );
break; break;
case 'updated_at': case 'updated_at':

View File

@ -68,7 +68,7 @@ function getFieldIndex_Row_LoggerHelper($field, array $row, array $fieldFilters,
{ {
switch ($field) { switch ($field) {
case 'title': case 'title':
return anchor(current_url() . '/view/' . $row['uid'], $row[$field], ["target" => "_self"]); return anchor(current_url() . '/view/' . $row['uid'], $row[$field], [...$attributes, "target" => "_self"]);
break; break;
case 'user_uid': case 'user_uid':
case 'status': case 'status':

View File

@ -65,7 +65,7 @@ function getFieldIndex_Row_UserSNSHelper($field, array $row, array $fieldFilters
{ {
switch ($field) { switch ($field) {
case 'name': case 'name':
return anchor(current_url() . '/view/' . $row['uid'], $row[$field], ["target" => "_self"]); return anchor(current_url() . '/view/' . $row['uid'], $row[$field], [...$attributes, "target" => "_self"]);
break; break;
case 'updated_at': case 'updated_at':
case 'created_at': case 'created_at':

View File

@ -69,7 +69,7 @@ function getFieldIndex_Row_UserHelper($field, array $row, array $fieldFilters, $
{ {
switch ($field) { switch ($field) {
case 'id': case 'id':
return anchor(current_url() . '/view/' . $row['uid'], $row[$field], ["target" => "_self"]); return anchor(current_url() . '/view/' . $row['uid'], $row[$field], [...$attributes, "target" => "_self"]);
break; break;
case 'updated_at': case 'updated_at':
case 'created_at': case 'created_at':

View File

@ -0,0 +1,51 @@
<?php
namespace App\Models;
use App\Entities\BaseEntity;
//계층형구조구현용 모델(게시판,카테고리 등등)
abstract class BaseHierarchyModel extends BaseModel
{
protected function __construct()
{
parent::__construct();
$this->allowedFields = [...$this->allowedFields, 'grpno', 'grporder', 'grpdepth'];
$this->validationRules = [
...$this->validationRules,
'grpno' => 'if_exist|numeric',
'grporder' => 'if_exist|numeric',
'grpdepth' => 'if_exist|numeric',
];
}
abstract public function getEntity($uid): BaseEntity;
abstract public function getEntitys($where): array;
abstract function reply($parent_entity, array $formDatas): BaseEntity;
final protected function create_process($entity, array $formDatas)
{
$entity = parent::create_process($entity, $formDatas);
//생성시는 grpno가 primarykey와 같음
$this->builder()->set('grpno', $entity->getPrimaryKey());
$this->builder()->where($this->primaryKey, $entity->getPrimaryKey());
$this->builder()->update();
return $entity;
}
final protected function reply_process($parent_entity, $entity, array $formDatas)
{
//부모의 그룹과 grpno가 같고, 부모의 grporder보다 1 큰것을 grporder+1을 해서 update
//escape -> false옵션 반드시 있어야함
$this->builder()->set('grporder', 'grporder+1', false);
$this->builder()->where([
'grpno' => $parent_entity->grpno,
'grporder >' => $parent_entity->grporder
]);
$this->builder()->update();
//reply용 설정
$entity->grpno = $parent_entity->grpno;
$entity->grporder = $parent_entity->grporder + 1;
$entity->grpdepth = $parent_entity->grpdepth + 1;
return parent::create_process($entity, $formDatas);
}
}

View File

@ -9,7 +9,7 @@ use App\Entities\BaseEntity;
abstract class BaseModel extends Model abstract class BaseModel extends Model
{ {
protected $DBGroup = 'default'; protected $DBGroup = 'default';
// protected $table = 'user'; protected $table = 'default';
protected $primaryKey = 'uid'; protected $primaryKey = 'uid';
protected $useAutoIncrement = true; protected $useAutoIncrement = true;
protected $insertID = 0; protected $insertID = 0;
@ -41,9 +41,25 @@ abstract class BaseModel extends Model
protected $beforeDelete = []; protected $beforeDelete = [];
protected $afterDelete = []; protected $afterDelete = [];
abstract public function getEntityByField($field, $value): ?BaseEntity; protected function __construct()
abstract public function getEntity($uid): ?BaseEntity; {
abstract public function getFieldFormOptions(): array; parent::__construct();
$this->allowedFields = ['updated_at', 'created_at'];
$this->validationRules = [
'updated_at' => 'if_exist|valid_date',
'created_at' => 'if_exist|valid_date',
];
}
abstract public function getEntity($uid): BaseEntity;
abstract public function getEntitys($where): array;
final public function getFieldFormOptions($where, $options = array()): array
{
foreach ($this->getEntitys($where) as $entity) {
$options[$entity->getPrimaryKey()] = $entity->getTitle();
}
return $options;
}
final public function getUUID() final public function getUUID()
{ {
@ -58,39 +74,15 @@ abstract class BaseModel extends Model
); );
} }
//계층형구조구현 //create , modify 직전 작업용 작업
final protected function create_hierarchy($entity)
{
//생성시는 grpno가 primarykey와 같음
//escape -> false옵션 반드시 있어야함
$this->builder()->set('grpno', $entity->getPrimaryKey(), false);
$this->builder()->where($this->primaryKey, $entity->getPrimaryKey());
$this->builder()->update();
return $entity;
}
final protected function reply_hierarchy($entity, $parent_entity)
{
//부모의 그룹과 grpno가 같고, 부모의 grporder보다 1 큰것을 grporder+1을 해서 update
//escape -> false옵션 반드시 있어야함
$this->builder()->set('grporder', 'grporder+1', false);
$this->builder()->where([
'grpno' => $parent_entity->grpno,
'grporder >' => $parent_entity->grporder
]);
$this->builder()->update();
//reply용 설정
$entity->grpno = $parent_entity->grpno;
$entity->grporder = $parent_entity->grporder + 1;
$entity->grpdepth = $parent_entity->grpdepth + 1;
return $entity;
}
protected function changeFormData($field, array $formDatas, $entity) protected function changeFormData($field, array $formDatas, $entity)
{ {
switch ($field) { switch ($field) {
case $this->primaryKey: case $this->primaryKey:
//primaryKey가 자동입력이 아니면
if (!$this->useAutoIncrement) { if (!$this->useAutoIncrement) {
$entity->$field = $this->getUUID(); $pk = $this->primaryKey;
$entity->$pk = $this->getUUID();
} }
break; break;
case 'user_uid': case 'user_uid':
@ -128,19 +120,24 @@ abstract class BaseModel extends Model
Log::add("error", implode("\n", $this->errors())); Log::add("error", implode("\n", $this->errors()));
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->errors(), true)); throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->errors(), true));
} }
//primaryKey가 자동입력이면
if ($this->useAutoIncrement) {
$pk = $this->primaryKey;
$entity->$pk = $this->insertID();
}
} else { } else {
throw new \Exception(__FUNCTION__ . " 오류 발생.\n 기존정보와 동일하여 수정되지 않았습니다."); throw new \Exception(__FUNCTION__ . " 오류 발생.\n 기존정보와 동일하여 수정되지 않았습니다.");
} }
return $entity; return $entity;
} }
final protected function create_process($entity, array $formDatas) protected function create_process($entity, array $formDatas)
{ {
foreach ($this->allowedFields as $field) { foreach ($this->allowedFields as $field) {
$entity = $this->changeFormData($field, $formDatas, $entity); $entity = $this->changeFormData($field, $formDatas, $entity);
} }
return $this->save_process($entity); return $this->save_process($entity);
} }
final protected function modify_process($entity, array $formDatas) protected function modify_process($entity, array $formDatas)
{ {
foreach ($this->allowedFields as $field) { foreach ($this->allowedFields as $field) {
if ($field != $this->primaryKey) { if ($field != $this->primaryKey) {
@ -158,8 +155,6 @@ abstract class BaseModel extends Model
$this->builder()->set($field, "{$field}+{$cnt}", false); $this->builder()->set($field, "{$field}+{$cnt}", false);
$this->builder()->where($this->primaryKey, $uid); $this->builder()->where($this->primaryKey, $uid);
$this->builder()->update(); $this->builder()->update();
// echo $this->getLastQuery();
// exit;
} }
//Index관련 //Index관련

View File

@ -6,11 +6,14 @@ use App\Entities\BoardConfigEntity;
class BoardConfigModel extends BaseModel class BoardConfigModel extends BaseModel
{ {
protected $table = 'tw_board_config'; public function __construct()
protected $primaryKey = 'uid'; {
protected $useAutoIncrement = false; parent::__construct();
protected $allowedFields = ['uid', 'name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'head', 'tail', 'status', 'updated_at']; $this->table = 'tw_board_config';
protected $validationRules = [ $this->useAutoIncrement = false;
$this->allowedFields = [...$this->allowedFields, 'uid', 'name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'head', 'tail', 'status'];
$this->validationRules = [
...$this->validationRules,
'uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]', 'uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
'name' => 'required|string', 'name' => 'required|string',
'isaccess' => 'required', 'isaccess' => 'required',
@ -22,28 +25,17 @@ class BoardConfigModel extends BaseModel
'head' => 'if_exist|string', 'head' => 'if_exist|string',
'tail' => 'if_exist|string', 'tail' => 'if_exist|string',
'status' => 'if_exist|string', 'status' => 'if_exist|string',
'updated_at' => 'if_exist|valid_date',
'created_at' => 'if_exist|valid_date',
]; ];
}
public function getEntityByField($field, $value): ?BoardConfigEntity public function getEntity($uid): BoardConfigEntity
{ {
$entity = $this->asObject(BoardConfigEntity::class)->where($field, $value)->first(); $entity = $this->asObject(BoardConfigEntity::class)->where([$this->primaryKey => $uid])->first();
if (is_null($entity)) { return $entity ?: throw new \Exception("{$uid}의 해당 데이터가 없습니다.\n ");
throw new \Exception("해당 데이터가 없습니다.\n {$field}->{$value}");
} }
return $entity; public function getEntitys($where): array
}
public function getEntity($uid): ?BoardConfigEntity
{ {
return $this->getEntityByField($this->primaryKey, $uid); return $this->asObject(BoardConfigEntity::class)->where($where)->findAll();
}
public function getFieldFormOptions(array $wheres = array(), $temps = array()): array
{
foreach ($this->asObject(BoardConfigEntity::class)->where($wheres)->findAll() as $entity) {
$temps[$entity->getPrimaryKey()] = $entity->getTitle();
}
return $temps;
} }
protected function changeFormData($field, array $formDatas, $entity) protected function changeFormData($field, array $formDatas, $entity)

View File

@ -4,16 +4,15 @@ namespace App\Models;
use App\Entities\BoardEntity; use App\Entities\BoardEntity;
class BoardModel extends BaseModel class BoardModel extends BaseHierarchyModel
{ {
protected $table = 'tw_board'; public function __construct()
protected $primaryKey = 'uid'; {
protected $useAutoIncrement = true; parent::__construct();
protected $allowedFields = ['grpno', 'grporder', 'grpdepth', 'board_config_uid', 'user_uid', 'title', 'content', 'passwd', 'view_cnt', 'status', 'updated_at']; $this->table = 'tw_board';
protected $validationRules = [ $this->allowedFields = [...$this->allowedFields, 'board_config_uid', 'user_uid', 'title', 'content', 'passwd', 'view_cnt', 'status'];
'grpno' => 'if_exist|numeric', $this->validationRules = [
'grporder' => 'if_exist|numeric', ...$this->validationRules,
'grpdepth' => 'if_exist|numeric',
'board_config_uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]', 'board_config_uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
'user_uid' => 'if_exist|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]', 'user_uid' => 'if_exist|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
'title' => 'required|string', 'title' => 'required|string',
@ -21,45 +20,29 @@ class BoardModel extends BaseModel
'passwd' => 'if_exist|trim|string', 'passwd' => 'if_exist|trim|string',
'view_cnt' => 'if_exist|numeric', 'view_cnt' => 'if_exist|numeric',
'status' => 'if_exist|string', 'status' => 'if_exist|string',
'updated_at' => 'if_exist|valid_date',
'created_at' => 'if_exist|valid_date',
]; ];
public function getEntityByField($field, $value): ?BoardEntity
{
$entity = $this->asObject(BoardEntity::class)->where($field, $value)->first();
if (is_null($entity)) {
throw new \Exception("해당 데이터가 없습니다.\n {$field}->{$value}");
}
return $entity;
}
public function getEntity($uid): ?BoardEntity
{
return $this->getEntityByField($this->primaryKey, $uid);
}
public function getFieldFormOptions(array $wheres = array(), $temps = array()): array
{
foreach ($this->asObject(BoardEntity::class)->where($wheres)->findAll() as $entity) {
$temps[$entity->getPrimaryKey()] = $entity->getTitle();
}
return $temps;
} }
public function getEntity($uid): BoardEntity
{
$entity = $this->asObject(BoardEntity::class)->where([$this->primaryKey => $uid])->first();
return $entity ?: throw new \Exception("{$uid}의 해당 데이터가 없습니다.\n ");
}
public function getEntitys($where): array
{
return $this->asObject(BoardEntity::class)->where($where)->findAll();
}
public function create(array $formDatas): BoardEntity public function create(array $formDatas): BoardEntity
{ {
//계층형 Create return $this->create_process(new BoardEntity(), $formDatas);
$entity = $this->create_process(new BoardEntity(), $formDatas);
return $this->create_hierarchy($entity);
} }
public function modify(BoardEntity $entity, array $formDatas): BoardEntity public function modify(BoardEntity $entity, array $formDatas): BoardEntity
{ {
return $this->modify_process($entity, $formDatas); return $this->modify_process($entity, $formDatas);
} }
public function reply(BoardEntity $parent_entity, array $formDatas): BoardEntity public function reply($parent_entity, array $formDatas): BoardEntity
{ {
//계층형 Reply return $this->reply_process($parent_entity, new BoardEntity(), $formDatas);
$entity = $this->reply_hierarchy(new BoardEntity(), $parent_entity);
return $this->create_process($entity, $formDatas);
} }
//Index관련 //Index관련

View File

@ -6,37 +6,28 @@ use App\Entities\LoggerEntity;
class LoggerModel extends BaseModel class LoggerModel extends BaseModel
{ {
protected $table = 'tw_logger'; public function __construct()
protected $primaryKey = 'uid'; {
// protected $useAutoIncrement = true; parent::__construct();
protected $allowedFields = ['user_uid', 'title', 'content', 'status', 'updated_at']; $this->table = 'tw_logger';
protected $validationRules = [ $this->allowedFields = [...$this->allowedFields, 'user_uid', 'title', 'content', 'status'];
$this->validationRules = [
...$this->validationRules,
'user_uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]', 'user_uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
'title' => 'required|string', 'title' => 'required|string',
'content' => 'if_exist|string', 'content' => 'if_exist|string',
'status' => 'required|string', 'status' => 'required|string',
'updated_at' => 'if_exist|valid_date',
'created_at' => 'if_exist|valid_date',
]; ];
}
public function getEntityByField($field, $value): ?LoggerEntity public function getEntity($uid): LoggerEntity
{ {
$entity = $this->asObject(LoggerEntity::class)->where($field, $value)->first(); $entity = $this->asObject(LoggerEntity::class)->where([$this->primaryKey => $uid])->first();
if (is_null($entity)) { return $entity ?: throw new \Exception("{$uid}의 해당 데이터가 없습니다.\n ");
throw new \Exception("해당 데이터가 없습니다.\n {$field}->{$value}");
} }
return $entity; public function getEntitys($where): array
}
public function getEntity($uid): ?LoggerEntity
{ {
return $this->getEntityByField($this->primaryKey, $uid); return $this->asObject(LoggerEntity::class)->where($where)->findAll();
}
public function getFieldFormOptions(array $wheres = array(), $temps = array()): array
{
foreach ($this->asObject(LoggerEntity::class)->where($wheres)->findAll() as $entity) {
$temps[$entity->getPrimaryKey()] = $entity->getTitle();
}
return $temps;
} }
public function create(array $formDatas): LoggerEntity public function create(array $formDatas): LoggerEntity
{ {

View File

@ -6,11 +6,14 @@ use App\Entities\UserEntity;
class UserModel extends BaseModel class UserModel extends BaseModel
{ {
protected $table = 'tw_user'; public function __construct()
protected $primaryKey = 'uid'; {
protected $useAutoIncrement = false; parent::__construct();
protected $allowedFields = ['uid', 'id', 'email', 'passwd', 'name', 'role', 'status', 'updated_at']; $this->table = 'tw_user';
protected $validationRules = [ $this->useAutoIncrement = false;
$this->allowedFields = [...$this->allowedFields, 'uid', 'id', 'email', 'passwd', 'name', 'role', 'status'];
$this->validationRules = [
...$this->validationRules,
'uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]', 'uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
'id' => 'required|min_length[4]|max_length[20]', 'id' => 'required|min_length[4]|max_length[20]',
'passwd' => 'required|trim|min_length[4]|max_length[150]', 'passwd' => 'required|trim|min_length[4]|max_length[150]',
@ -18,28 +21,17 @@ class UserModel extends BaseModel
'email' => 'required|valid_email', 'email' => 'required|valid_email',
'role' => 'required|string', 'role' => 'required|string',
'status' => 'if_exist|string', 'status' => 'if_exist|string',
'updated_at' => 'if_exist|valid_date',
'created_at' => 'if_exist|valid_date',
]; ];
}
public function getEntityByField($field, $value): ?UserEntity public function getEntity($uid): UserEntity
{ {
$entity = $this->asObject(UserEntity::class)->where($field, $value)->first(); $entity = $this->asObject(UserEntity::class)->where([$this->primaryKey => $uid])->first();
if (is_null($entity)) { return $entity ?: throw new \Exception("{$uid}의 해당 데이터가 없습니다.\n ");
throw new \Exception("해당 데이터가 없습니다.\n {$field}->{$value}");
} }
return $entity; public function getEntitys($where): array
}
public function getEntity($uid): ?UserEntity
{ {
return $this->getEntityByField($this->primaryKey, $uid); return $this->asObject(UserEntity::class)->where($where)->findAll();
}
public function getFieldFormOptions(array $wheres = array(), $temps = array()): array
{
foreach ($this->asObject(UserEntity::class)->where($wheres)->findAll() as $entity) {
$temps[$entity->getPrimaryKey()] = $entity->getTitle();
}
return $temps;
} }
public function create(array $formDatas): UserEntity public function create(array $formDatas): UserEntity
{ {

View File

@ -6,11 +6,13 @@ use App\Entities\UserSNSEntity;
class UserSNSModel extends BaseModel class UserSNSModel extends BaseModel
{ {
protected $table = 'tw_user_sns'; public function __construct()
protected $primaryKey = 'uid'; {
// protected $useAutoIncrement = true; parent::__construct();
protected $allowedFields = ['user_uid', 'site', 'id', 'name', 'email', 'detail', 'status', 'updated_at', 'created_at']; $this->table = 'tw_user_sns';
protected $validationRules = [ $this->allowedFields = [...$this->allowedFields, 'user_uid', 'site', 'id', 'name', 'email', 'detail', 'status'];
$this->validationRules = [
...$this->validationRules,
'user_uid' => 'if_exist|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]', 'user_uid' => 'if_exist|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
'site' => 'required|string', 'site' => 'required|string',
'id' => 'required|string', 'id' => 'required|string',
@ -18,28 +20,17 @@ class UserSNSModel extends BaseModel
'email' => 'required|valid_email', 'email' => 'required|valid_email',
'detail' => 'if_exist|string', 'detail' => 'if_exist|string',
'status' => 'required|string', 'status' => 'required|string',
'updated_at' => 'if_exist|valid_date',
'created_at' => 'if_exist|valid_date',
]; ];
}
public function getEntityByField($field, $value): ?UserSNSEntity public function getEntity($uid): UserSNSEntity
{ {
$entity = $this->asObject(UserSNSEntity::class)->where($field, $value)->first(); $entity = $this->asObject(UserSNSEntity::class)->where([$this->primaryKey => $uid])->first();
if (is_null($entity)) { return $entity ?: throw new \Exception("{$uid}의 해당 데이터가 없습니다.\n ");
throw new \Exception("해당 데이터가 없습니다.\n {$field}->{$value}");
} }
return $entity; public function getEntitys($where): array
}
public function getEntity($uid): ?UserSNSEntity
{ {
return $this->getEntityByField($this->primaryKey, $uid); return $this->asObject(UserSNSEntity::class)->where($where)->findAll();
}
public function getFieldFormOptions(array $wheres = array(), $temps = array()): array
{
foreach ($this->asObject(UserSNSEntity::class)->where($wheres)->findAll() as $entity) {
$temps[$entity->getPrimaryKey()] = $entity->getTitle();
}
return $temps;
} }
public function create(array $formDatas): UserSNSEntity public function create(array $formDatas): UserSNSEntity

31
tests/OOPExampleTest.php Normal file
View File

@ -0,0 +1,31 @@
<?
class Foo
{
}
class NotFoo
{
}
class Bar
{
/**
* @param $_foos Foo[]
*/
public function doFoo(array $_foos, $_param2)
{
return (function (Foo ...$_foos) use ($_param2) {
return $_param2;
})(...$_foos);
}
}
$myBar = new Bar();
$arrayOfFoo = array(new Foo(), new Foo(), new Foo());
$notArrayOfFoo = array(new Foo(), new NotFoo(), new Foo());
echo $myBar->doFoo($arrayOfFoo, 'Success');
// Success
echo $myBar->doFoo($notArrayOfFoo, 'Success');
// Uncaught TypeError: Argument 2 passed to Bar::{closure}() must be an instance of Foo, instance of NotFoo given...