Automation/app/Libraries/MyAuth/MyAuth.php
2024-09-16 14:13:10 +09:00

59 lines
1.3 KiB
PHP

<?php
namespace App\Libraries\MyAuth;
use App\Entities\UserEntity;
use App\Models\UserModel;
use App\Models\SNSUserModel;
// 참고:https://github.com/SyntaxPhoenix/iloclient
abstract class MyAuth
{
private $_userModel = null;
private $_snsUserModel = null;
protected $_session = null;
protected function __construct()
{
$this->_session = \Config\Services::session();
}
abstract public function getAuthButton();
abstract public function execute(): UserEntity;
final protected function getUserModel(): UserModel
{
if (is_null($this->_userModel)) {
$this->_userModel = new UserModel();
}
return $this->_userModel;
}
final protected function getUserSNSModel(): SNSUSerModel
{
if (is_null($this->_snsUserModel)) {
$this->_snsUserModel = new SNSUserModel();
}
return $this->_snsUserModel;
}
protected function setSession_process(UserEntity $entity): UserEntity
{
$this->_session->set(SESSION_NAMES['ISLOGIN'], true);
$auths = [];
foreach (array_values(AUTH_FIELDS) as $field) {
switch ($field) {
case 'id':
$auths[$field] = $entity->getPK();
break;
case 'title':
$auths[$field] = $entity->getTitle();
break;
case 'role':
$auths[$field] = $entity->$field;
break;
}
}
$this->_session->set(SESSION_NAMES['AUTH'], $auths);
return $entity;
}
}