内核代码升级
This commit is contained in:
@@ -89,7 +89,7 @@ return [
|
||||
'url_route_must' => false,
|
||||
// 域名部署
|
||||
'url_domain_deploy' => false,
|
||||
// 域名根,如.thinkphp.cn
|
||||
// 域名根,如thinkphp.cn
|
||||
'url_domain_root' => '',
|
||||
// 是否自动转换URL中的控制器和操作名
|
||||
'url_convert' => true,
|
||||
|
||||
@@ -18,6 +18,8 @@ use think\Config;
|
||||
use think\Cookie;
|
||||
use think\Db;
|
||||
use think\Debug;
|
||||
use think\exception\HttpException;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\Lang;
|
||||
use think\Loader;
|
||||
use think\Log;
|
||||
@@ -345,9 +347,10 @@ if (!function_exists('cache')) {
|
||||
* @param mixed $name 缓存名称,如果为数组表示进行缓存设置
|
||||
* @param mixed $value 缓存值
|
||||
* @param mixed $options 缓存参数
|
||||
* @param string $tag 缓存标签
|
||||
* @return mixed
|
||||
*/
|
||||
function cache($name, $value = '', $options = null)
|
||||
function cache($name, $value = '', $options = null, $tag = null)
|
||||
{
|
||||
if (is_array($options)) {
|
||||
// 缓存操作的同时初始化
|
||||
@@ -369,7 +372,11 @@ if (!function_exists('cache')) {
|
||||
} else {
|
||||
$expire = is_numeric($options) ? $options : null; //默认快捷缓存设置过期时间
|
||||
}
|
||||
return Cache::set($name, $value, $expire);
|
||||
if (is_null($tag)) {
|
||||
return Cache::set($name, $value, $expire);
|
||||
} else {
|
||||
return Cache::tag($tag)->set($name, $value, $expire);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -505,9 +512,9 @@ if (!function_exists('abort')) {
|
||||
function abort($code, $message = null, $header = [])
|
||||
{
|
||||
if ($code instanceof Response) {
|
||||
throw new \think\exception\HttpResponseException($code);
|
||||
throw new HttpResponseException($code);
|
||||
} else {
|
||||
throw new \think\exception\HttpException($code, $message, null, $header);
|
||||
throw new HttpException($code, $message, null, $header);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -520,7 +527,7 @@ if (!function_exists('halt')) {
|
||||
function halt($var)
|
||||
{
|
||||
dump($var);
|
||||
throw new \think\exception\HttpResponseException(new Response);
|
||||
throw new HttpResponseException(new Response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -529,6 +536,7 @@ if (!function_exists('token')) {
|
||||
* 生成表单令牌
|
||||
* @param string $name 令牌名称
|
||||
* @param mixed $type 令牌生成方法
|
||||
* @return string
|
||||
*/
|
||||
function token($name = '__token__', $type = 'md5')
|
||||
{
|
||||
|
||||
@@ -61,4 +61,5 @@ return [
|
||||
'cache write error' => '缓存写入失败',
|
||||
'sae mc write error' => 'SAE mc 写入错误',
|
||||
'route name not exists' => '路由标识不存在(或参数不够)',
|
||||
'invalid request' => '非法请求',
|
||||
];
|
||||
|
||||
@@ -327,7 +327,7 @@ class App
|
||||
$actionName = $convert ? strtolower($actionName) : $actionName;
|
||||
|
||||
// 设置当前请求的控制器、操作
|
||||
$request->controller($controller)->action($actionName);
|
||||
$request->controller(Loader::parseName($controller, 1))->action($actionName);
|
||||
|
||||
// 监听module_init
|
||||
Hook::listen('module_init', $request);
|
||||
|
||||
@@ -44,7 +44,7 @@ class Cache
|
||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\cache\\driver\\' . ucwords($type);
|
||||
|
||||
// 记录初始化信息
|
||||
App::$debug && Log::record('[ CACHE ] INIT ' . $type . ':' . var_export($options, true), 'info');
|
||||
App::$debug && Log::record('[ CACHE ] INIT ' . $type, 'info');
|
||||
if (true === $name) {
|
||||
return new $class($options);
|
||||
} else {
|
||||
|
||||
@@ -38,7 +38,7 @@ class Controller
|
||||
|
||||
/**
|
||||
* 架构函数
|
||||
* @param Request $request Request对象
|
||||
* @param Request $request Request对象
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(Request $request = null)
|
||||
@@ -70,8 +70,8 @@ class Controller
|
||||
/**
|
||||
* 前置操作
|
||||
* @access protected
|
||||
* @param string $method 前置操作方法名
|
||||
* @param array $options 调用参数 ['only'=>[...]] 或者['except'=>[...]]
|
||||
* @param string $method 前置操作方法名
|
||||
* @param array $options 调用参数 ['only'=>[...]] 或者['except'=>[...]]
|
||||
*/
|
||||
protected function beforeAction($method, $options = [])
|
||||
{
|
||||
@@ -91,18 +91,16 @@ class Controller
|
||||
}
|
||||
}
|
||||
|
||||
if (method_exists($this, $method)) {
|
||||
call_user_func([$this, $method]);
|
||||
}
|
||||
call_user_func([$this, $method]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载模板输出
|
||||
* @access protected
|
||||
* @param string $template 模板文件名
|
||||
* @param array $vars 模板输出变量
|
||||
* @param array $replace 模板替换
|
||||
* @param array $config 模板参数
|
||||
* @param string $template 模板文件名
|
||||
* @param array $vars 模板输出变量
|
||||
* @param array $replace 模板替换
|
||||
* @param array $config 模板参数
|
||||
* @return mixed
|
||||
*/
|
||||
protected function fetch($template = '', $vars = [], $replace = [], $config = [])
|
||||
@@ -113,10 +111,10 @@ class Controller
|
||||
/**
|
||||
* 渲染内容输出
|
||||
* @access protected
|
||||
* @param string $content 模板内容
|
||||
* @param array $vars 模板输出变量
|
||||
* @param array $replace 替换内容
|
||||
* @param array $config 模板参数
|
||||
* @param string $content 模板内容
|
||||
* @param array $vars 模板输出变量
|
||||
* @param array $replace 替换内容
|
||||
* @param array $config 模板参数
|
||||
* @return mixed
|
||||
*/
|
||||
protected function display($content = '', $vars = [], $replace = [], $config = [])
|
||||
@@ -127,8 +125,8 @@ class Controller
|
||||
/**
|
||||
* 模板变量赋值
|
||||
* @access protected
|
||||
* @param mixed $name 要显示的模板变量
|
||||
* @param mixed $value 变量的值
|
||||
* @param mixed $name 要显示的模板变量
|
||||
* @param mixed $value 变量的值
|
||||
* @return void
|
||||
*/
|
||||
protected function assign($name, $value = '')
|
||||
|
||||
@@ -75,7 +75,9 @@ class Db
|
||||
}
|
||||
$class = false !== strpos($options['type'], '\\') ? $options['type'] : '\\think\\db\\connector\\' . ucwords($options['type']);
|
||||
// 记录初始化信息
|
||||
App::$debug && Log::record('[ DB ] INIT ' . $options['type'] . ':' . var_export($options, true), 'info');
|
||||
if (App::$debug) {
|
||||
Log::record('[ DB ] INIT ' . $options['type'], 'info');
|
||||
}
|
||||
if (true === $name) {
|
||||
return new $class($options);
|
||||
} else {
|
||||
|
||||
@@ -452,13 +452,14 @@ class Loader
|
||||
}
|
||||
|
||||
/**
|
||||
* 实例化数据库
|
||||
* @param mixed $config 数据库配置
|
||||
* @return object
|
||||
* 数据库初始化 并取得数据库类实例
|
||||
* @param mixed $config 数据库配置
|
||||
* @param bool|string $name 连接标识 true 强制重新连接
|
||||
* @return \think\db\Connection
|
||||
*/
|
||||
public static function db($config = [])
|
||||
public static function db($config = [], $name = false)
|
||||
{
|
||||
return Db::connect($config);
|
||||
return Db::connect($config, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -61,7 +61,7 @@ class Log
|
||||
throw new ClassNotFoundException('class not exists:' . $class, $class);
|
||||
}
|
||||
// 记录初始化信息
|
||||
App::$debug && Log::record('[ LOG ] INIT ' . $type . ': ' . var_export($config, true), 'info');
|
||||
App::$debug && Log::record('[ LOG ] INIT ' . $type, 'info');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -321,6 +321,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
}
|
||||
switch ($type) {
|
||||
case 'datetime':
|
||||
case 'date':
|
||||
$format = !empty($param) ? $param : $this->dateFormat;
|
||||
$value = date($format, $_SERVER['REQUEST_TIME']);
|
||||
break;
|
||||
|
||||
@@ -240,7 +240,7 @@ class Request
|
||||
$options['baseUrl'] = $info['path'];
|
||||
$options['pathinfo'] = '/' == $info['path'] ? '/' : ltrim($info['path'], '/');
|
||||
$options['method'] = $server['REQUEST_METHOD'];
|
||||
$options['domain'] = $server['HTTP_HOST'];
|
||||
$options['domain'] = $info['scheme'] . '://' . $server['HTTP_HOST'];
|
||||
$options['content'] = $content;
|
||||
self::$instance = new self($options);
|
||||
return self::$instance;
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace think;
|
||||
|
||||
use think\Config;
|
||||
use think\Debug;
|
||||
use think\Env;
|
||||
use think\response\Json as JsonResponse;
|
||||
use think\response\Jsonp as JsonpResponse;
|
||||
use think\response\Redirect as RedirectResponse;
|
||||
@@ -96,7 +97,7 @@ class Response
|
||||
$data = $this->getContent();
|
||||
|
||||
// Trace调试注入
|
||||
if (Config::get('app_trace')) {
|
||||
if (Env::get('app_trace', Config::get('app_trace'))) {
|
||||
Debug::inject($this, $data);
|
||||
}
|
||||
|
||||
|
||||
@@ -422,6 +422,8 @@ class Route
|
||||
}
|
||||
$vars = self::parseVar($key);
|
||||
$item[] = ['rule' => $key, 'route' => $route, 'var' => $vars, 'option' => $options, 'pattern' => $patterns];
|
||||
// 设置路由标识
|
||||
self::$name[$route][] = [$key, $vars, self::$domain];
|
||||
}
|
||||
self::$rules['*'][$name] = ['rule' => $item, 'route' => '', 'var' => [], 'option' => $option, 'pattern' => $pattern];
|
||||
}
|
||||
@@ -1170,6 +1172,9 @@ class Route
|
||||
self::parseUrlParams(empty($path) ? '' : implode('/', $path));
|
||||
// 封装路由
|
||||
$route = [$module, $controller, $action];
|
||||
if (isset(self::$name[implode($depr, $route)])) {
|
||||
throw new HttpException(404, 'invalid request:' . $url);
|
||||
}
|
||||
}
|
||||
return ['type' => 'module', 'module' => $route];
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
namespace think;
|
||||
|
||||
use think\Config;
|
||||
use think\Loader;
|
||||
use think\Request;
|
||||
use think\Route;
|
||||
|
||||
@@ -157,7 +158,7 @@ class Url
|
||||
$module = $module ? $module . '/' : '';
|
||||
}
|
||||
|
||||
$controller = $request->controller();
|
||||
$controller = Loader::parseName($request->controller());
|
||||
if ('' == $url) {
|
||||
// 空字符串输出当前的 模块/控制器/操作
|
||||
$url = $module . $controller . '/' . $request->action();
|
||||
|
||||
@@ -546,7 +546,7 @@ class Validate
|
||||
$result = is_numeric($value);
|
||||
break;
|
||||
case 'integer':
|
||||
// 是否为整形
|
||||
// 是否为整型
|
||||
$result = $this->filter($value, FILTER_VALIDATE_INT);
|
||||
break;
|
||||
case 'email':
|
||||
|
||||
@@ -403,7 +403,11 @@ class Query
|
||||
$result = $pdo->fetchColumn();
|
||||
if (isset($cache)) {
|
||||
// 缓存数据
|
||||
Cache::set($key, $result, $cache['expire']);
|
||||
if (isset($cache['tag'])) {
|
||||
Cache::tag($cache['tag'])->set($key, $result, $cache['expire']);
|
||||
} else {
|
||||
Cache::set($key, $result, $cache['expire']);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 清空查询条件
|
||||
@@ -468,7 +472,11 @@ class Query
|
||||
}
|
||||
if (isset($cache) && isset($guid)) {
|
||||
// 缓存数据
|
||||
Cache::set($guid, $result, $cache['expire']);
|
||||
if (isset($cache['tag'])) {
|
||||
Cache::tag($cache['tag'])->set($guid, $result, $cache['expire']);
|
||||
} else {
|
||||
Cache::set($guid, $result, $cache['expire']);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 清空查询条件
|
||||
@@ -999,7 +1007,8 @@ class Query
|
||||
if (!$simple) {
|
||||
$options = $this->getOptions();
|
||||
$total = $this->count();
|
||||
$results = $this->options($options)->page($page, $listRows)->select();
|
||||
$bind = $this->bind;
|
||||
$results = $this->options($options)->bind($bind)->page($page, $listRows)->select();
|
||||
} else {
|
||||
$results = $this->limit(($page - 1) * $listRows, $listRows + 1)->select();
|
||||
$total = null;
|
||||
@@ -1067,9 +1076,10 @@ class Query
|
||||
* @access public
|
||||
* @param mixed $key 缓存key
|
||||
* @param integer $expire 缓存有效期
|
||||
* @param string $tag 缓存标签
|
||||
* @return $this
|
||||
*/
|
||||
public function cache($key = true, $expire = null)
|
||||
public function cache($key = true, $expire = null, $tag = null)
|
||||
{
|
||||
// 增加快捷调用方式 cache(10) 等同于 cache(true, 10)
|
||||
if (is_numeric($key) && is_null($expire)) {
|
||||
@@ -1077,7 +1087,7 @@ class Query
|
||||
$key = true;
|
||||
}
|
||||
if (false !== $key) {
|
||||
$this->options['cache'] = ['key' => $key, 'expire' => $expire];
|
||||
$this->options['cache'] = ['key' => $key, 'expire' => $expire, 'tag' => $tag];
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
@@ -1363,7 +1373,7 @@ class Query
|
||||
$tableName = $this->parseSqlTable($tableName);
|
||||
}
|
||||
|
||||
$guid = $tableName;
|
||||
list($guid) = explode(' ', $tableName);
|
||||
if (!isset(self::$info[$guid])) {
|
||||
$info = $this->connection->getFields($tableName);
|
||||
$fields = array_keys($info);
|
||||
@@ -1881,7 +1891,11 @@ class Query
|
||||
|
||||
if (isset($cache)) {
|
||||
// 缓存数据集
|
||||
Cache::set($key, $resultSet, $cache['expire']);
|
||||
if (isset($cache['tag'])) {
|
||||
Cache::tag($cache['tag'])->set($key, $resultSet, $cache['expire']);
|
||||
} else {
|
||||
Cache::set($key, $resultSet, $cache['expire']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1968,7 +1982,11 @@ class Query
|
||||
|
||||
if (isset($cache)) {
|
||||
// 缓存数据
|
||||
Cache::set($key, $result, $cache['expire']);
|
||||
if (isset($cache['tag'])) {
|
||||
Cache::tag($cache['tag'])->set($key, $result, $cache['expire']);
|
||||
} else {
|
||||
Cache::set($key, $result, $cache['expire']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ class Relation
|
||||
$result = $this->belongsToManyQuery($relation, $this->middle, $foreignKey, $localKey, $condition)->select();
|
||||
foreach ($result as $set) {
|
||||
$pivot = [];
|
||||
foreach ($set->toArray() as $key => $val) {
|
||||
foreach ($set->getData() as $key => $val) {
|
||||
if (strpos($key, '__')) {
|
||||
list($name, $attr) = explode('__', $key, 2);
|
||||
if ('pivot' == $name) {
|
||||
@@ -308,7 +308,7 @@ class Relation
|
||||
protected function match($model, $relation, &$result)
|
||||
{
|
||||
// 重新组装模型数据
|
||||
foreach ($result->toArray() as $key => $val) {
|
||||
foreach ($result->getData() as $key => $val) {
|
||||
if (strpos($key, '__')) {
|
||||
list($name, $attr) = explode('__', $key, 2);
|
||||
if ($name == $relation) {
|
||||
@@ -369,7 +369,7 @@ class Relation
|
||||
$data = [];
|
||||
foreach ($list as $set) {
|
||||
$pivot = [];
|
||||
foreach ($set->toArray() as $key => $val) {
|
||||
foreach ($set->getData() as $key => $val) {
|
||||
if (strpos($key, '__')) {
|
||||
list($name, $attr) = explode('__', $key, 2);
|
||||
if ('pivot' == $name) {
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace think\view\driver;
|
||||
|
||||
use think\App;
|
||||
use think\exception\TemplateNotFoundException;
|
||||
use think\Loader;
|
||||
use think\Log;
|
||||
use think\Request;
|
||||
|
||||
@@ -117,7 +118,7 @@ class Php
|
||||
|
||||
// 分析模板文件规则
|
||||
$request = Request::instance();
|
||||
$controller = $request->controller();
|
||||
$controller = Loader::parseName($request->controller());
|
||||
if ($controller && 0 !== strpos($template, '/')) {
|
||||
$depr = $this->config['view_depr'];
|
||||
$template = str_replace(['/', ':'], $depr, $template);
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace think\view\driver;
|
||||
|
||||
use think\App;
|
||||
use think\exception\TemplateNotFoundException;
|
||||
use think\Loader;
|
||||
use think\Log;
|
||||
use think\Request;
|
||||
use think\Template;
|
||||
@@ -114,7 +115,7 @@ class Think
|
||||
|
||||
// 分析模板文件规则
|
||||
$request = Request::instance();
|
||||
$controller = $request->controller();
|
||||
$controller = Loader::parseName($request->controller());
|
||||
if ($controller && 0 !== strpos($template, '/')) {
|
||||
$depr = $this->config['view_depr'];
|
||||
$template = str_replace(['/', ':'], $depr, $template);
|
||||
|
||||
Reference in New Issue
Block a user