格式化 start、base、traits 和 App、Config、Error、Loader 代码的样式。其他代码的样式待处理。

This commit is contained in:
Lin07ux
2017-11-05 15:21:42 +08:00
committed by ThinkPHP
parent 0fb51680e8
commit 35e763c8ff
9 changed files with 682 additions and 513 deletions

View File

@@ -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);
}
}