4

PHP单例模式加载所需的类

 1 year ago
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单例模式加载所需的类

发布:25分钟前 更新:25分钟前 folder_open 计算机编程语言 PHP编程 comment

原文地址: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;
    }
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK