feat: admin login
This commit is contained in:
46
app/Service/Common/AppMakeService.php
Normal file
46
app/Service/Common/AppMakeService.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Common;
|
||||
|
||||
use Exception;
|
||||
use Hyperf\Context\Context;
|
||||
|
||||
class AppMakeService
|
||||
{
|
||||
/**
|
||||
* 生成类对象
|
||||
* @param $className
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function make($className): mixed
|
||||
{
|
||||
if (!class_exists($className)) throw new Exception('The instantiated class does not exist');
|
||||
|
||||
$array = Context::get('obj');
|
||||
if (!isset($array[$className])) {
|
||||
$array = $array ?? [];
|
||||
$array[$className] = new $className;
|
||||
Context::set('obj', $array);
|
||||
}
|
||||
|
||||
return $array[$className];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对象类
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getObj(): mixed
|
||||
{
|
||||
return Context::get('obj');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user