Automation init...2

This commit is contained in:
최준흠 2024-09-09 13:51:33 +09:00
parent 1973a55bfb
commit 0bd684e8fe
3 changed files with 14 additions and 8 deletions

View File

@ -41,7 +41,7 @@ abstract class BaseController extends Controller
* Be sure to declare properties for any property fetch you initialized.
* The creation of dynamic property is deprecated in PHP 8.2.
*/
// protected $session;
protected $session;
/**
* @return void

View File

@ -3,16 +3,23 @@
namespace App\Controllers;
use App\Controllers\BaseController;
use App\Trait\AuthTrait;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Traits\AuthTrait;
abstract class CommonController extends BaseController
{
use AuthTrait;
private $_datas = [];
protected function __construct()
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
$this->_datas['session'] = $this->login_check();
// Do Not Edit This Line
parent::initController($request, $response, $logger);
// Preload any models, libraries, etc, here.
// E.g.: $this->session = \Config\Services::session();
$this->session = $this->login_check();
}
final public function __get($name): array|null

View File

@ -1,16 +1,15 @@
<?php
namespace App\Trait;
namespace App\Traits;
trait AuthTrait
{
public function login_check(): array
{
//사용자 기본 Role 지정
$session = [];
$session[SESSION['NAMES']['ISLOGIN']] = false;
$session['currentRoles'] = [DEFAULTS["ROLE"]];
if ($this->_session->get(SESSION['NAMES']['ISLOGIN'])) {
if (\Config\Services::session()->get(SESSION['NAMES']['ISLOGIN'])) {
$session[SESSION['NAMES']['ISLOGIN']] = true;
$session['auth'] = $this->_session->get(SESSION['NAMES']['AUTH']);
$currentRoles = explode(DEFAULTS['DELIMITER_ROLE'], $session['auth'][AUTH['FIELDS']['ROLE']]);