servermgrv2/app/Libraries/Adapter/Auth/Adapter.php
2023-07-19 20:59:23 +09:00

61 lines
1.4 KiB
PHP

<?php
namespace App\Libraries\Adapter\Auth;
use App\Models\UserModel;
use App\Models\UserSNSModel;
use App\Entities\UserEntity;
// 참고:https://github.com/SyntaxPhoenix/iloclient
abstract class Adapter
{
private $_site = null;
private $_userModel = null;
private $_userSNSModel = null;
protected $_debug = false;
protected function __construct(string $site, $debug = false)
{
$this->_site = $site;
$this->_debug = $debug;
}
final public function getSiteName(): string
{
if (is_null($this->_site)) {
throw new \Exception("Auth Adpater Site명이 정의 되지 않았습니다.");
}
return ucfirst($this->_site);
}
abstract public function getAuthButton();
abstract public function signin(array $formDatas): UserEntity;
final protected function getUserModel(): UserModel
{
if (is_null($this->_userModel)) {
$this->_userModel = new UserModel();
}
return $this->_userModel;
}
final protected function getUserSNSModel(): UserSNSModel
{
if (is_null($this->_userSNSModel)) {
$this->_userSNSModel = new UserSNSModel();
}
return $this->_userSNSModel;
}
protected function setUserSession(UserEntity $entity): void
{
session()->set(LOGINS['ISLOGIN'], true);
$datas = array();
foreach (LOGINS['USER']['FIELDS'] as $field) {
$datas[$field] = $entity->$field;
}
session()->set(array(LOGINS['USER']['NAME'] => $datas));
}
protected function getUserSession(): array
{
return session()->get(LOGINS['USER']['NAME']);
}
}