This commit is contained in:
thinkphp
2016-07-12 11:36:48 +08:00

View File

@@ -27,19 +27,20 @@ use think\Session;
use think\Url; use think\Url;
use think\View; use think\View;
if (!function_exists('load_trait')) {
/** /**
* 快速导入Traits PHP5.5以上无需调用 * 快速导入Traits PHP5.5以上无需调用
* @param string $class trait库 * @param string $class trait库
* @param string $ext 类库后缀 * @param string $ext 类库后缀
* @return boolean * @return boolean
*/ */
if (!function_exists('load_trait')) {
function load_trait($class, $ext = EXT) function load_trait($class, $ext = EXT)
{ {
return Loader::import($class, TRAIT_PATH, $ext); return Loader::import($class, TRAIT_PATH, $ext);
} }
} }
if (!function_exists('exception')) {
/** /**
* 抛出异常处理 * 抛出异常处理
* *
@@ -49,7 +50,6 @@ if (!function_exists('load_trait')) {
* *
* @throws Exception * @throws Exception
*/ */
if (!function_exists('exception')) {
function exception($msg, $code = 0, $exception = '') function exception($msg, $code = 0, $exception = '')
{ {
$e = $exception ?: '\think\Exception'; $e = $exception ?: '\think\Exception';
@@ -57,6 +57,7 @@ if (!function_exists('exception')) {
} }
} }
if (!function_exists('debug')) {
/** /**
* 记录时间(微秒)和内存使用情况 * 记录时间(微秒)和内存使用情况
* @param string $start 开始标签 * @param string $start 开始标签
@@ -64,7 +65,6 @@ if (!function_exists('exception')) {
* @param integer|string $dec 小数位 如果是m 表示统计内存占用 * @param integer|string $dec 小数位 如果是m 表示统计内存占用
* @return mixed * @return mixed
*/ */
if (!function_exists('debug')) {
function debug($start, $end = '', $dec = 6) function debug($start, $end = '', $dec = 6)
{ {
if ('' == $end) { if ('' == $end) {
@@ -75,6 +75,7 @@ if (!function_exists('debug')) {
} }
} }
if (!function_exists('lang')) {
/** /**
* 获取语言变量值 * 获取语言变量值
* @param string $name 语言变量名 * @param string $name 语言变量名
@@ -82,13 +83,13 @@ if (!function_exists('debug')) {
* @param string $lang 语言 * @param string $lang 语言
* @return mixed * @return mixed
*/ */
if (!function_exists('lang')) {
function lang($name, $vars = [], $lang = '') function lang($name, $vars = [], $lang = '')
{ {
return Lang::get($name, $vars, $lang); return Lang::get($name, $vars, $lang);
} }
} }
if (!function_exists('config')) {
/** /**
* 获取和设置配置参数 * 获取和设置配置参数
* @param string|array $name 参数名 * @param string|array $name 参数名
@@ -96,7 +97,6 @@ if (!function_exists('lang')) {
* @param string $range 作用域 * @param string $range 作用域
* @return mixed * @return mixed
*/ */
if (!function_exists('config')) {
function config($name = '', $value = null, $range = '') function config($name = '', $value = null, $range = '')
{ {
if (is_null($value) && is_string($name)) { if (is_null($value) && is_string($name)) {
@@ -107,6 +107,7 @@ if (!function_exists('config')) {
} }
} }
if (!function_exists('input')) {
/** /**
* 获取输入数据 支持默认值和过滤 * 获取输入数据 支持默认值和过滤
* @param string $key 获取的变量名 * @param string $key 获取的变量名
@@ -114,7 +115,6 @@ if (!function_exists('config')) {
* @param string $filter 过滤方法 * @param string $filter 过滤方法
* @return mixed * @return mixed
*/ */
if (!function_exists('input')) {
function input($key, $default = null, $filter = null) function input($key, $default = null, $filter = null)
{ {
if (0 === strpos($key, '?')) { if (0 === strpos($key, '?')) {
@@ -141,19 +141,20 @@ if (!function_exists('input')) {
} }
} }
if (!function_exists('widget')) {
/** /**
* 渲染输出Widget * 渲染输出Widget
* @param string $name Widget名称 * @param string $name Widget名称
* @param array $data 传人的参数 * @param array $data 传人的参数
* @return mixed * @return mixed
*/ */
if (!function_exists('widget')) {
function widget($name, $data = []) function widget($name, $data = [])
{ {
return Loader::action($name, $data, 'widget'); return Loader::action($name, $data, 'widget');
} }
} }
if (!function_exists('model')) {
/** /**
* 实例化Model * 实例化Model
* @param string $name Model名称 * @param string $name Model名称
@@ -161,13 +162,13 @@ if (!function_exists('widget')) {
* @param bool $appendSuffix 是否添加类名后缀 * @param bool $appendSuffix 是否添加类名后缀
* @return \think\Model * @return \think\Model
*/ */
if (!function_exists('model')) {
function model($name = '', $layer = 'model', $appendSuffix = false) function model($name = '', $layer = 'model', $appendSuffix = false)
{ {
return Loader::model($name, $layer, $appendSuffix); return Loader::model($name, $layer, $appendSuffix);
} }
} }
if (!function_exists('validate')) {
/** /**
* 实例化验证器 * 实例化验证器
* @param string $name 验证器名称 * @param string $name 验证器名称
@@ -175,26 +176,26 @@ if (!function_exists('model')) {
* @param bool $appendSuffix 是否添加类名后缀 * @param bool $appendSuffix 是否添加类名后缀
* @return \think\Validate * @return \think\Validate
*/ */
if (!function_exists('validate')) {
function validate($name = '', $layer = 'validate', $appendSuffix = false) function validate($name = '', $layer = 'validate', $appendSuffix = false)
{ {
return Loader::validate($name, $layer, $appendSuffix); return Loader::validate($name, $layer, $appendSuffix);
} }
} }
if (!function_exists('db')) {
/** /**
* 实例化数据库类 * 实例化数据库类
* @param string $name 操作的数据表名称(不含前缀) * @param string $name 操作的数据表名称(不含前缀)
* @param array|string $config 数据库配置参数 * @param array|string $config 数据库配置参数
* @return \think\db\Query * @return \think\db\Query
*/ */
if (!function_exists('db')) {
function db($name = '', $config = []) function db($name = '', $config = [])
{ {
return Db::connect($config)->name($name); return Db::connect($config)->name($name);
} }
} }
if (!function_exists('controller')) {
/** /**
* 实例化控制器 格式:[模块/]控制器 * 实例化控制器 格式:[模块/]控制器
* @param string $name 资源地址 * @param string $name 资源地址
@@ -202,13 +203,13 @@ if (!function_exists('db')) {
* @param bool $appendSuffix 是否添加类名后缀 * @param bool $appendSuffix 是否添加类名后缀
* @return \think\Controller * @return \think\Controller
*/ */
if (!function_exists('controller')) {
function controller($name, $layer = 'controller', $appendSuffix = false) function controller($name, $layer = 'controller', $appendSuffix = false)
{ {
return Loader::controller($name, $layer, $appendSuffix); return Loader::controller($name, $layer, $appendSuffix);
} }
} }
if (!function_exists('action')) {
/** /**
* 调用模块的操作方法 参数格式 [模块/控制器/]操作 * 调用模块的操作方法 参数格式 [模块/控制器/]操作
* @param string $url 调用地址 * @param string $url 调用地址
@@ -217,13 +218,13 @@ if (!function_exists('controller')) {
* @param bool $appendSuffix 是否添加类名后缀 * @param bool $appendSuffix 是否添加类名后缀
* @return mixed * @return mixed
*/ */
if (!function_exists('action')) {
function action($url, $vars = [], $layer = 'controller', $appendSuffix = false) function action($url, $vars = [], $layer = 'controller', $appendSuffix = false)
{ {
return Loader::action($url, $vars, $layer, $appendSuffix); return Loader::action($url, $vars, $layer, $appendSuffix);
} }
} }
if (!function_exists('import')) {
/** /**
* 导入所需的类库 同java的Import 本函数有缓存功能 * 导入所需的类库 同java的Import 本函数有缓存功能
* @param string $class 类库命名空间字符串 * @param string $class 类库命名空间字符串
@@ -231,26 +232,26 @@ if (!function_exists('action')) {
* @param string $ext 导入的文件扩展名 * @param string $ext 导入的文件扩展名
* @return boolean * @return boolean
*/ */
if (!function_exists('import')) {
function import($class, $baseUrl = '', $ext = EXT) function import($class, $baseUrl = '', $ext = EXT)
{ {
return Loader::import($class, $baseUrl, $ext); return Loader::import($class, $baseUrl, $ext);
} }
} }
if (!function_exists('vendor')) {
/** /**
* 快速导入第三方框架类库 所有第三方框架的类库文件统一放到 系统的Vendor目录下面 * 快速导入第三方框架类库 所有第三方框架的类库文件统一放到 系统的Vendor目录下面
* @param string $class 类库 * @param string $class 类库
* @param string $ext 类库后缀 * @param string $ext 类库后缀
* @return boolean * @return boolean
*/ */
if (!function_exists('vendor')) {
function vendor($class, $ext = EXT) function vendor($class, $ext = EXT)
{ {
return Loader::import($class, VENDOR_PATH, $ext); return Loader::import($class, VENDOR_PATH, $ext);
} }
} }
if (!function_exists('dump')) {
/** /**
* 浏览器友好的变量输出 * 浏览器友好的变量输出
* @param mixed $var 变量 * @param mixed $var 变量
@@ -258,13 +259,13 @@ if (!function_exists('vendor')) {
* @param string $label 标签 默认为空 * @param string $label 标签 默认为空
* @return void|string * @return void|string
*/ */
if (!function_exists('dump')) {
function dump($var, $echo = true, $label = null) function dump($var, $echo = true, $label = null)
{ {
return Debug::dump($var, $echo, $label); return Debug::dump($var, $echo, $label);
} }
} }
if (!function_exists('url')) {
/** /**
* Url生成 * Url生成
* @param string $url 路由地址 * @param string $url 路由地址
@@ -273,13 +274,13 @@ if (!function_exists('dump')) {
* @param bool|string $domain 域名 * @param bool|string $domain 域名
* @return string * @return string
*/ */
if (!function_exists('url')) {
function url($url = '', $vars = '', $suffix = true, $domain = false) function url($url = '', $vars = '', $suffix = true, $domain = false)
{ {
return Url::build($url, $vars, $suffix, $domain); return Url::build($url, $vars, $suffix, $domain);
} }
} }
if (!function_exists('session')) {
/** /**
* Session管理 * Session管理
* @param string|array $name session名称如果为数组表示进行session设置 * @param string|array $name session名称如果为数组表示进行session设置
@@ -287,7 +288,6 @@ if (!function_exists('url')) {
* @param string $prefix 前缀 * @param string $prefix 前缀
* @return mixed * @return mixed
*/ */
if (!function_exists('session')) {
function session($name, $value = '', $prefix = null) function session($name, $value = '', $prefix = null)
{ {
if (is_array($name)) { if (is_array($name)) {
@@ -309,6 +309,7 @@ if (!function_exists('session')) {
} }
} }
if (!function_exists('cookie')) {
/** /**
* Cookie管理 * Cookie管理
* @param string|array $name cookie名称如果为数组表示进行cookie设置 * @param string|array $name cookie名称如果为数组表示进行cookie设置
@@ -316,7 +317,6 @@ if (!function_exists('session')) {
* @param mixed $option 参数 * @param mixed $option 参数
* @return mixed * @return mixed
*/ */
if (!function_exists('cookie')) {
function cookie($name, $value = '', $option = null) function cookie($name, $value = '', $option = null)
{ {
if (is_array($name)) { if (is_array($name)) {
@@ -338,6 +338,7 @@ if (!function_exists('cookie')) {
} }
} }
if (!function_exists('cache')) {
/** /**
* 缓存管理 * 缓存管理
* @param mixed $name 缓存名称,如果为数组表示进行缓存设置 * @param mixed $name 缓存名称,如果为数组表示进行缓存设置
@@ -345,7 +346,6 @@ if (!function_exists('cookie')) {
* @param mixed $options 缓存参数 * @param mixed $options 缓存参数
* @return mixed * @return mixed
*/ */
if (!function_exists('cache')) {
function cache($name, $value = '', $options = null) function cache($name, $value = '', $options = null)
{ {
if (is_array($options)) { if (is_array($options)) {
@@ -373,13 +373,13 @@ if (!function_exists('cache')) {
} }
} }
if (!function_exists('trace')) {
/** /**
* 记录日志信息 * 记录日志信息
* @param mixed $log log信息 支持字符串和数组 * @param mixed $log log信息 支持字符串和数组
* @param string $level 日志级别 * @param string $level 日志级别
* @return void|array * @return void|array
*/ */
if (!function_exists('trace')) {
function trace($log = '[think]', $level = 'log') function trace($log = '[think]', $level = 'log')
{ {
if ('[think]' === $log) { if ('[think]' === $log) {
@@ -390,17 +390,18 @@ if (!function_exists('trace')) {
} }
} }
if (!function_exists('request')) {
/** /**
* 获取当前Request对象实例 * 获取当前Request对象实例
* @return Request * @return Request
*/ */
if (!function_exists('request')) {
function request() function request()
{ {
return Request::instance(); return Request::instance();
} }
} }
if (!function_exists('response')) {
/** /**
* 创建普通 Response 对象实例 * 创建普通 Response 对象实例
* @param mixed $data 输出数据 * @param mixed $data 输出数据
@@ -409,13 +410,13 @@ if (!function_exists('request')) {
* @param string $type * @param string $type
* @return Response * @return Response
*/ */
if (!function_exists('response')) {
function response($data = [], $code = 200, $header = [], $type = 'html') function response($data = [], $code = 200, $header = [], $type = 'html')
{ {
return Response::create($data, $type, $code, $header); return Response::create($data, $type, $code, $header);
} }
} }
if (!function_exists('view')) {
/** /**
* 渲染模板输出 * 渲染模板输出
* @param string $template 模板文件 * @param string $template 模板文件
@@ -423,13 +424,13 @@ if (!function_exists('response')) {
* @param integer $code 状态码 * @param integer $code 状态码
* @return \think\response\View * @return \think\response\View
*/ */
if (!function_exists('view')) {
function view($template = '', $vars = [], $code = 200) function view($template = '', $vars = [], $code = 200)
{ {
return Response::create($template, 'view', $code)->vars($vars); return Response::create($template, 'view', $code)->vars($vars);
} }
} }
if (!function_exists('json')) {
/** /**
* 获取\think\response\Json对象实例 * 获取\think\response\Json对象实例
* @param mixed $data 返回的数据 * @param mixed $data 返回的数据
@@ -438,13 +439,13 @@ if (!function_exists('view')) {
* @param array $options 参数 * @param array $options 参数
* @return \think\response\Json * @return \think\response\Json
*/ */
if (!function_exists('json')) {
function json($data = [], $code = 200, $header = [], $options = []) function json($data = [], $code = 200, $header = [], $options = [])
{ {
return Response::create($data, 'json', $code, $header, $options); return Response::create($data, 'json', $code, $header, $options);
} }
} }
if (!function_exists('jsonp')) {
/** /**
* 获取\think\response\Jsonp对象实例 * 获取\think\response\Jsonp对象实例
* @param mixed $data 返回的数据 * @param mixed $data 返回的数据
@@ -453,13 +454,13 @@ if (!function_exists('json')) {
* @param array $options 参数 * @param array $options 参数
* @return \think\response\Jsonp * @return \think\response\Jsonp
*/ */
if (!function_exists('jsonp')) {
function jsonp($data = [], $code = 200, $header = [], $options = []) function jsonp($data = [], $code = 200, $header = [], $options = [])
{ {
return Response::create($data, 'jsonp', $code, $header, $options); return Response::create($data, 'jsonp', $code, $header, $options);
} }
} }
if (!function_exists('xml')) {
/** /**
* 获取\think\response\Xml对象实例 * 获取\think\response\Xml对象实例
* @param mixed $data 返回的数据 * @param mixed $data 返回的数据
@@ -468,13 +469,13 @@ if (!function_exists('jsonp')) {
* @param array $options 参数 * @param array $options 参数
* @return \think\response\Xml * @return \think\response\Xml
*/ */
if (!function_exists('xml')) {
function xml($data = [], $code = 200, $header = [], $options = []) function xml($data = [], $code = 200, $header = [], $options = [])
{ {
return Response::create($data, 'xml', $code, $header, $options); return Response::create($data, 'xml', $code, $header, $options);
} }
} }
if (!function_exists('redirect')) {
/** /**
* 获取\think\response\Redirect对象实例 * 获取\think\response\Redirect对象实例
* @param mixed $url 重定向地址 支持Url::build方法的地址 * @param mixed $url 重定向地址 支持Url::build方法的地址
@@ -482,7 +483,6 @@ if (!function_exists('xml')) {
* @param integer $code 状态码 * @param integer $code 状态码
* @return \think\response\Redirect * @return \think\response\Redirect
*/ */
if (!function_exists('redirect')) {
function redirect($url = [], $params = [], $code = 302) function redirect($url = [], $params = [], $code = 302)
{ {
if (is_integer($params)) { if (is_integer($params)) {
@@ -493,13 +493,13 @@ if (!function_exists('redirect')) {
} }
} }
if (!function_exists('abort')) {
/** /**
* 抛出HTTP异常 * 抛出HTTP异常
* @param integer $code 状态码 * @param integer $code 状态码
* @param string $message 错误信息 * @param string $message 错误信息
* @param array $header 参数 * @param array $header 参数
*/ */
if (!function_exists('abort')) {
function abort($code, $message = null, $header = []) function abort($code, $message = null, $header = [])
{ {
throw new \think\exception\HttpException($code, $message, null, $header); throw new \think\exception\HttpException($code, $message, null, $header);