

PHP单例模式加载所需的类
source link: https://www.iplayio.cn/post/09497686
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
原文地址:PHP单例模式加载所需的类
PHP单例模式加载所需的类
class LogicLoader
{
private static $instance = null;
private function __construct()
{
}
private function __wakeup()
{
}
private function __clone()
{
}
public function __invoke(){
}
/**
* @param string $name
* @param array $arguments
* @return mixed
* @throws Exception
*/
public static function __callStatic(string $name, array $arguments)
{
$logic = "app\\common\logic\\" . $name;
if (self::$instance === null || !self::$instance instanceof $logic) {
self::$instance = new $logic(...$arguments);
}
return self::$instance;
}
}
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK