mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
格式化 start、base、traits 和 App、Config、Error、Loader 代码的样式。其他代码的样式待处理。
This commit is contained in:
@@ -15,31 +15,40 @@ use think\Exception;
|
||||
|
||||
trait Instance
|
||||
{
|
||||
/**
|
||||
* @var null|static 实例对象
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
* 获取示例
|
||||
* @param array $options 实例配置
|
||||
* @return static
|
||||
*/
|
||||
public static function instance($options = [])
|
||||
{
|
||||
if (is_null(self::$instance)) {
|
||||
self::$instance = new self($options);
|
||||
}
|
||||
if (is_null(self::$instance)) self::$instance = new self($options);
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
// 静态调用
|
||||
public static function __callStatic($method, $params)
|
||||
/**
|
||||
* 静态调用
|
||||
* @param string $method 调用方法
|
||||
* @param array $params 调用参数
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function __callStatic($method, array $params)
|
||||
{
|
||||
if (is_null(self::$instance)) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
if (is_null(self::$instance)) self::$instance = new self();
|
||||
|
||||
$call = substr($method, 1);
|
||||
if (0 === strpos($method, '_') && is_callable([self::$instance, $call])) {
|
||||
return call_user_func_array([self::$instance, $call], $params);
|
||||
} else {
|
||||
|
||||
if (0 !== strpos($method, '_') || !is_callable([self::$instance, $call])) {
|
||||
throw new Exception("method not exists:" . $method);
|
||||
}
|
||||
|
||||
return call_user_func_array([self::$instance, $call], $params);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user