Browse Source

[更新]ThinkPHP版本回退到v5.1.16 解决路由兼容问题

Anyon 6 years ago
parent
commit
77ee26ad45

+ 1 - 1
composer.json

@@ -18,7 +18,7 @@
   "require": {
     "php": ">=5.6.0",
     "endroid/qr-code": "^1.9",
-    "topthink/framework": "5.1.*",
+    "topthink/framework": "5.1.16",
     "zoujingli/ip2region": "dev-master",
     "aliyuncs/oss-sdk-php": "^2.2",
     "zoujingli/weopen-developer": "dev-master",

+ 26 - 2
thinkphp/library/think/App.php

@@ -20,7 +20,7 @@ use think\route\Dispatch;
  */
 class App extends Container
 {
-    const VERSION = '5.1.17';
+    const VERSION = '5.1.16';
 
     /**
      * 当前模块路径
@@ -333,6 +333,7 @@ class App extends Container
             // 对容器中的对象实例进行配置更新
             $this->containerConfigUpdate($module);
         }
+
     }
 
     protected function containerConfigUpdate($module)
@@ -426,7 +427,30 @@ class App extends Container
         }
 
         $this->middleware->add(function (Request $request, $next) use ($dispatch, $data) {
-            return is_null($data) ? $dispatch->run() : $data;
+            if (is_null($data)) {
+                try {
+                    // 执行调度
+                    $data = $dispatch->run();
+                } catch (HttpResponseException $exception) {
+                    $data = $exception->getResponse();
+                }
+            }
+
+            // 输出数据到客户端
+            if ($data instanceof Response) {
+                $response = $data;
+            } elseif (!is_null($data)) {
+                // 默认自动识别响应输出类型
+                $isAjax = $request->isAjax();
+                $type   = $isAjax ? $this->config('app.default_ajax_return') : $this->config('app.default_return_type');
+
+                $response = Response::create($data, $type);
+            } else {
+                $data     = ob_get_clean();
+                $status   = empty($data) ? 204 : 200;
+                $response = Response::create($data, '', $status);
+            }
+            return $response;
         });
 
         $response = $this->middleware->dispatch($this->request);

+ 2 - 25
thinkphp/library/think/Controller.php

@@ -43,18 +43,12 @@ class Controller
     protected $batchValidate = false;
 
     /**
-     * 前置操作方法列表(即将废弃)
+     * 前置操作方法列表
      * @var array $beforeActionList
      */
     protected $beforeActionList = [];
 
     /**
-     * 控制器中间件
-     * @var array
-     */
-    protected $middleware = [];
-
-    /**
      * 构造方法
      * @access public
      */
@@ -67,24 +61,7 @@ class Controller
         // 控制器初始化
         $this->initialize();
 
-        // 控制器中间件
-        if ($this->middleware) {
-            foreach ($this->middleware as $key => $val) {
-                if (!is_int($key)) {
-                    if (isset($val['only']) && !in_array($this->request->action(), $val['only'])) {
-                        continue;
-                    } elseif (isset($val['except']) && in_array($this->request->action(), $val['except'])) {
-                        continue;
-                    } else {
-                        $val = $key;
-                    }
-                }
-
-                $this->app['middleware']->controller($val);
-            }
-        }
-
-        // 前置操作方法 即将废弃
+        // 前置操作方法
         foreach ((array) $this->beforeActionList as $method => $options) {
             is_numeric($method) ?
             $this->beforeAction($options) :

+ 1 - 1
thinkphp/library/think/Log.php

@@ -117,7 +117,7 @@ class Log implements LoggerInterface
             return;
         }
 
-        if (is_string($msg) && !empty($context)) {
+        if (is_string($msg)) {
             $replace = [];
             foreach ($context as $key => $val) {
                 $replace['{' . $key . '}'] = $val;

+ 22 - 56
thinkphp/library/think/Middleware.php

@@ -39,95 +39,62 @@ class Middleware
         $this->config = array_merge($this->config, $config);
     }
 
-    /**
-     * 导入中间件
-     * @access public
-     * @param  array  $middlewares
-     * @param  string $type  中间件类型
-     */
-    public function import(array $middlewares = [], $type = 'route')
+    public function import(array $middlewares = [])
     {
         foreach ($middlewares as $middleware) {
-            $this->add($middleware, $type);
+            $this->add($middleware);
         }
     }
 
     /**
-     * 注册中间件
-     * @access public
-     * @param  mixed  $middleware
-     * @param  string $type  中间件类型
+     * {@inheritdoc}
      */
-    public function add($middleware, $type = 'route')
+    public function add($middleware)
     {
         if (is_null($middleware)) {
             return;
         }
 
-        $middleware = $this->buildMiddleware($middleware, $type);
+        $middleware = $this->buildMiddleware($middleware);
 
         if ($middleware) {
-            $this->queue[$type][] = $middleware;
+            $this->queue[] = $middleware;
         }
     }
 
     /**
-     * 注册控制器中间件
-     * @access public
-     * @param  mixed  $middleware
-     */
-    public function controller($middleware)
-    {
-        return $this->add($middleware, 'controller');
-    }
-
-    /**
-     * 移除中间件
-     * @access public
-     * @param  mixed  $middleware
-     * @param  string $type  中间件类型
+     * {@inheritdoc}
      */
-    public function unshift($middleware, $type = 'route')
+    public function unshift($middleware)
     {
         if (is_null($middleware)) {
             return;
         }
 
-        $middleware = $this->buildMiddleware($middleware, $type);
+        $middleware = $this->buildMiddleware($middleware);
 
         if ($middleware) {
-            array_unshift($this->queue[$type], $middleware);
+            array_unshift($this->queue, $middleware);
         }
     }
 
     /**
-     * 获取注册的中间件
-     * @access public
-     * @param  string $type  中间件类型
+     * {@inheritdoc}
      */
-    public function all($type = 'route')
+    public function all()
     {
-        return $this->queue[$type] ?: [];
+        return $this->queue;
     }
 
     /**
-     * 中间件调度
-     * @access public
-     * @param  Request  $request
-     * @param  string   $type  中间件类型
+     * {@inheritdoc}
      */
-    public function dispatch(Request $request, $type = 'route')
+    public function dispatch(Request $request)
     {
-        return call_user_func($this->resolve($type), $request);
+        return call_user_func($this->resolve(), $request);
     }
 
-    /**
-     * 解析中间件
-     * @access protected
-     * @param  mixed  $middleware
-     * @param  string $type  中间件类型
-     */
-    protected function buildMiddleware($middleware, $type = 'route')
+    protected function buildMiddleware($middleware)
     {
         if (is_array($middleware)) {
             list($middleware, $param) = $middleware;
@@ -150,7 +117,7 @@ class Middleware
         }
 
         if (is_array($middleware)) {
-            return $this->import($middleware, $type);
+            return $this->import($middleware);
         }
 
         if (strpos($middleware, ':')) {
@@ -160,11 +127,10 @@ class Middleware
         return [[$this->app->make($middleware), 'handle'], isset($param) ? $param : null];
     }
 
-    protected function resolve($type = 'route')
+    protected function resolve()
     {
-        return function (Request $request) use ($type) {
-
-            $middleware = array_shift($this->queue[$type]);
+        return function (Request $request) {
+            $middleware = array_shift($this->queue);
 
             if (null === $middleware) {
                 throw new InvalidArgumentException('The queue was exhausted, with no response returned');
@@ -173,7 +139,7 @@ class Middleware
             list($call, $param) = $middleware;
 
             try {
-                $response = call_user_func_array($call, [$request, $this->resolve($type), $param]);
+                $response = call_user_func_array($call, [$request, $this->resolve(), $param]);
             } catch (HttpResponseException $exception) {
                 $response = $exception->getResponse();
             }

+ 4 - 4
thinkphp/library/think/Model.php

@@ -236,7 +236,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
         // 设置当前模型 确保查询返回模型对象
         $query = Db::connect($this->connection, false, $this->query);
         $query->model($this)
-            ->json($this->json, $this->jsonAssoc)
+            ->json($this->json)
             ->setJsonFieldType($this->jsonType);
 
         if (isset(static::$readMaster['*']) || isset(static::$readMaster[static::class])) {
@@ -284,7 +284,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
         $query = $this->buildQuery();
 
         // 软删除
-        if (property_exists($this, 'withTrashed') && !$this->withTrashed) {
+        if (method_exists($this, 'withNoTrashed')) {
             $this->withNoTrashed($query);
         }
 
@@ -750,6 +750,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
      */
     public function saveAll($dataSet, $replace = true)
     {
+        $result = [];
+
         $db = $this->db(false);
         $db->startTrans();
 
@@ -760,8 +762,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
                 $auto = true;
             }
 
-            $result = [];
-
             foreach ($dataSet as $key => $data) {
                 if ($this->exists || (!empty($auto) && isset($data[$pk]))) {
                     $result[$key] = self::update($data, [], $this->field);

+ 17 - 43
thinkphp/library/think/Request.php

@@ -11,9 +11,6 @@
 
 namespace think;
 
-use think\facade\Cookie;
-use think\facade\Session;
-
 class Request
 {
     /**
@@ -313,6 +310,7 @@ class Request
     {
         $request = new static($config->pull('app'));
 
+        $request->cookie = $app['cookie']->get();
         $request->server = $_SERVER;
         $request->env    = $app['env']->get();
 
@@ -763,19 +761,18 @@ class Request
     /**
      * 当前的请求类型
      * @access public
-     * @param  bool $origin  是否获取原始请求类型
+     * @param  bool $method  true 获取原始请求类型
      * @return string
      */
-    public function method($origin = false)
+    public function method($method = false)
     {
-        if ($origin) {
+        if (true === $method) {
             // 获取原始请求类型
             return $this->isCli() ? 'GET' : $this->server('REQUEST_METHOD');
         } elseif (!$this->method) {
             if (isset($_POST[$this->config['var_method']])) {
-                $this->method    = strtoupper($_POST[$this->config['var_method']]);
-                $method          = strtolower($this->method);
-                $this->{$method} = $_POST;
+                $this->method = strtoupper($_POST[$this->config['var_method']]);
+                $this->{$this->method}($_POST);
             } elseif ($this->server('HTTP_X_HTTP_METHOD_OVERRIDE')) {
                 $this->method = strtoupper($this->server('HTTP_X_HTTP_METHOD_OVERRIDE'));
             } else {
@@ -913,7 +910,6 @@ class Request
             // 获取包含文件上传信息的数组
             $file = $this->file();
             $data = is_array($file) ? array_merge($this->param, $file) : $this->param;
-
             return $this->input($data, '', $default, $filter);
         }
 
@@ -1064,16 +1060,14 @@ class Request
     public function session($name = '', $default = null)
     {
         if (empty($this->session)) {
-            $this->session = Session::get();
+            $this->session = facade\Session::get();
         }
 
         if ('' === $name) {
             return $this->session;
         }
 
-        $data = $this->getData($this->session, $name);
-
-        return is_null($data) ? $default : $data;
+        return isset($this->session[$name]) ? $this->session[$name] : $default;
     }
 
     /**
@@ -1086,12 +1080,8 @@ class Request
      */
     public function cookie($name = '', $default = null, $filter = '')
     {
-        if (empty($this->cookie)) {
-            $this->cookie = Cookie::get();
-        }
-
         if (!empty($name)) {
-            $data = Cookie::has($name) ? Cookie::get($name) : $default;
+            $data = isset($this->cookie[$name]) ? $this->cookie[$name] : $default;
         } else {
             $data = $this->cookie;
         }
@@ -1282,10 +1272,14 @@ class Request
                 list($name, $type) = explode('/', $name);
             }
 
-            $data = $this->getData($data, $name);
-
-            if (is_null($data)) {
-                return $default;
+            // 按.拆分成多维数组进行判断
+            foreach (explode('.', $name) as $val) {
+                if (isset($data[$val])) {
+                    $data = $data[$val];
+                } else {
+                    // 无输入数据,返回默认值
+                    return $default;
+                }
             }
 
             if (is_object($data)) {
@@ -1312,26 +1306,6 @@ class Request
     }
 
     /**
-     * 获取数据
-     * @access public
-     * @param  array         $data 数据源
-     * @param  string|false  $name 字段名
-     * @return mixed
-     */
-    protected function getData(array $data, $name)
-    {
-        foreach (explode('.', $name) as $val) {
-            if (isset($data[$val])) {
-                $data = $data[$val];
-            } else {
-                return;
-            }
-        }
-
-        return $data;
-    }
-
-    /**
      * 设置或获取当前的过滤规则
      * @access public
      * @param  mixed $filter 过滤规则

+ 0 - 27
thinkphp/library/think/Route.php

@@ -391,33 +391,6 @@ class Route
     }
 
     /**
-     * 读取路由
-     * @access public
-     * @param  string    $rule 路由规则
-     * @param  string    $domain 域名
-     * @return array
-     */
-    public function getRule($rule, $domain = null)
-    {
-        if (is_null($domain)) {
-            $domain = $this->domain;
-        }
-
-        return $this->app['rule_name']->getRule($rule, $domain);
-    }
-
-    /**
-     * 读取路由
-     * @access public
-     * @param  string    $domain 域名
-     * @return array
-     */
-    public function getRuleList($domain = null)
-    {
-        return $this->app['rule_name']->getRuleList($domain);
-    }
-
-    /**
      * 批量导入路由标识
      * @access public
      * @param  array    $name 路由标识

+ 6 - 11
thinkphp/library/think/Session.php

@@ -478,21 +478,16 @@ class Session
     public function has($name, $prefix = null)
     {
         empty($this->init) && $this->boot();
-
         $prefix = !is_null($prefix) ? $prefix : $this->prefix;
-        $value  = $prefix ? (!empty($_SESSION[$prefix]) ? $_SESSION[$prefix] : []) : $_SESSION;
 
-        $name = explode('.', $name);
+        if (strpos($name, '.')) {
+            // 支持数组
+            list($name1, $name2) = explode('.', $name);
 
-        foreach ($name as $val) {
-            if (!isset($value[$val])) {
-                return false;
-            } else {
-                $value = $value[$val];
-            }
+            return $prefix ? isset($_SESSION[$prefix][$name1][$name2]) : isset($_SESSION[$name1][$name2]);
+        } else {
+            return $prefix ? isset($_SESSION[$prefix][$name]) : isset($_SESSION[$name]);
         }
-
-        return true;
     }
 
     /**

+ 15 - 20
thinkphp/library/think/Validate.php

@@ -113,23 +113,12 @@ class Validate
     protected $currentScene = null;
 
     /**
-     * Filter_var 规则
-     * @var array
-     */
-    protected $filter = [
-        'email'   => FILTER_VALIDATE_EMAIL,
-        'ip'      => [FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6],
-        'integer' => FILTER_VALIDATE_INT,
-        'url'     => FILTER_VALIDATE_URL,
-        'macAddr' => FILTER_VALIDATE_MAC,
-        'float'   => FILTER_VALIDATE_FLOAT,
-    ];
-
-    /**
      * 内置正则验证规则
      * @var array
      */
     protected $regex = [
+        'alpha'       => '/^[A-Za-z]+$/',
+        'alphaNum'    => '/^[A-Za-z0-9]+$/',
         'alphaDash'   => '/^[A-Za-z0-9\-\_]+$/',
         'chs'         => '/^[\x{4e00}-\x{9fa5}]+$/u',
         'chsAlpha'    => '/^[\x{4e00}-\x{9fa5}a-zA-Z]+$/u',
@@ -141,6 +130,19 @@ class Validate
     ];
 
     /**
+     * Filter_var 规则
+     * @var array
+     */
+    protected $filter = [
+        'email'   => FILTER_VALIDATE_EMAIL,
+        'ip'      => [FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6],
+        'integer' => FILTER_VALIDATE_INT,
+        'url'     => FILTER_VALIDATE_URL,
+        'macAddr' => FILTER_VALIDATE_MAC,
+        'float'   => FILTER_VALIDATE_FLOAT,
+    ];
+
+    /**
      * 验证场景定义
      * @var array
      */
@@ -749,9 +751,6 @@ class Validate
             case 'number':
                 $result = ctype_digit((string) $value);
                 break;
-            case 'alphaNum':
-                $result = ctype_alnum($value);
-                break;
             case 'array':
                 // 是否为数组
                 $result = is_array($value);
@@ -769,10 +768,6 @@ class Validate
                 if (isset(self::$type[$rule])) {
                     // 注册的验证规则
                     $result = call_user_func_array(self::$type[$rule], [$value]);
-                } elseif (function_exists('ctype_' . $rule)) {
-                    // ctype验证规则
-                    $ctypeFun = 'ctype_' . $rule;
-                    $result   = $ctypeFun($value);
                 } elseif (isset($this->filter[$rule])) {
                     // Filter_var验证规则
                     $result = $this->filter($value, $this->filter[$rule]);

+ 5 - 2
thinkphp/library/think/db/Connection.php

@@ -1340,8 +1340,11 @@ abstract class Connection
 
         if (empty($options['fetch_sql']) && !empty($options['cache'])) {
             // 判断查询缓存
-            $cache  = $options['cache'];
-            $result = $this->getCacheData($query, $cache, null, $guid);
+            $cache = $options['cache'];
+
+            $guid = is_string($cache['key']) ? $cache['key'] : $this->getCacheKey($query, $field);
+
+            $result = Container::get('cache')->get($guid);
 
             if (false !== $result) {
                 return $result;

+ 8 - 36
thinkphp/library/think/db/Query.php

@@ -87,7 +87,7 @@ class Query
      * 读取主库的表
      * @var array
      */
-    protected static $readMaster = [];
+    private static $readMaster = [];
 
     /**
      * 日期查询表达式
@@ -635,11 +635,11 @@ class Query
      * COUNT查询
      * @access public
      * @param  string $field 字段名
-     * @return float|string
+     * @return integer|string
      */
     public function count($field = '*')
     {
-        if (!empty($this->options['group'])) {
+        if (isset($this->options['group'])) {
             // 支持GROUP
             $options = $this->getOptions();
             $subSql  = $this->options($options)->field('count(' . $field . ') AS think_count')->bind($this->bind)->buildSql();
@@ -660,7 +660,7 @@ class Query
      * SUM查询
      * @access public
      * @param  string $field 字段名
-     * @return float
+     * @return float|int
      */
     public function sum($field)
     {
@@ -695,7 +695,7 @@ class Query
      * AVG查询
      * @access public
      * @param  string $field 字段名
-     * @return float
+     * @return float|int
      */
     public function avg($field)
     {
@@ -2124,13 +2124,11 @@ class Query
      * 设置JSON字段信息
      * @access public
      * @param  array $json JSON字段
-     * @param  bool  $assoc 是否取出数组
      * @return $this
      */
-    public function json(array $json = [], $assoc = false)
+    public function json(array $json = [])
     {
-        $this->options['json']       = $json;
-        $this->options['json_assoc'] = $assoc;
+        $this->options['json'] = $json;
         return $this;
     }
 
@@ -2250,32 +2248,6 @@ class Query
     }
 
     /**
-     * 查询当前时间在两个时间字段范围
-     * @access public
-     * @param  string    $startField    开始时间字段
-     * @param  string    $endField 结束时间字段
-     * @return $this
-     */
-    public function whereBetweenTimeField($startField, $endField)
-    {
-        return $this->whereTime($startField, '<=', time())
-            ->whereTime($endField, '>=', time());
-    }
-
-    /**
-     * 查询当前时间不在两个时间字段范围
-     * @access public
-     * @param  string    $startField    开始时间字段
-     * @param  string    $endField 结束时间字段
-     * @return $this
-     */
-    public function whereNotBetweenTimeField($startField, $endField)
-    {
-        return $this->whereTime($startField, '>', time())
-            ->whereTime($endField, '<', time(), 'OR');
-    }
-
-    /**
      * 查询日期或者时间范围
      * @access public
      * @param  string    $field 日期字段名
@@ -2925,7 +2897,7 @@ class Query
     protected function resultToModel(&$result, $options = [], $resultSet = false)
     {
         if (!empty($options['json'])) {
-            $this->jsonResult($result, $options['json'], $options['json_assoc']);
+            $this->jsonResult($result, $options['json']);
         }
 
         $condition = (!$resultSet && isset($options['where']['AND'])) ? $options['where']['AND'] : null;

+ 0 - 94
thinkphp/library/think/db/connector/Sqlsrv.php

@@ -126,100 +126,6 @@ class Sqlsrv extends Connection
     }
 
     /**
-     * 得到某个列的数组
-     * @access public
-     * @param  Query     $query 查询对象
-     * @param  string    $field 字段名 多个字段用逗号分隔
-     * @param  string    $key   索引
-     * @return array
-     */
-    public function column(Query $query, $field, $key = '')
-    {
-        $options = $query->getOptions();
-
-        if (empty($options['fetch_sql']) && !empty($options['cache'])) {
-            // 判断查询缓存
-            $cache = $options['cache'];
-
-            $guid = is_string($cache['key']) ? $cache['key'] : $this->getCacheKey($query, $field);
-
-            $result = Container::get('cache')->get($guid);
-
-            if (false !== $result) {
-                return $result;
-            }
-        }
-
-        if (isset($options['field'])) {
-            $query->removeOption('field');
-        }
-
-        if (is_null($field)) {
-            $field = '*';
-        } elseif ($key && '*' != $field) {
-            $field = $key . ',' . $field;
-        }
-
-        if (is_string($field)) {
-            $field = array_map('trim', explode(',', $field));
-        }
-
-        $query->setOption('field', $field);
-
-        // 生成查询SQL
-        $sql = $this->builder->select($query);
-
-        $bind = $query->getBind();
-
-        if (!empty($options['fetch_sql'])) {
-            // 获取实际执行的SQL语句
-            return $this->getRealSql($sql, $bind);
-        }
-
-        // 执行查询操作
-        $pdo = $this->query($sql, $bind, $options['master'], true);
-
-        if (1 == $pdo->columnCount()) {
-            $result = $pdo->fetchAll(PDO::FETCH_COLUMN);
-        } else {
-            $resultSet = $pdo->fetchAll(PDO::FETCH_ASSOC);
-
-            if ('*' == $field && $key) {
-                $result = array_column($resultSet, null, $key);
-            } elseif ($resultSet) {
-                $fields = array_keys($resultSet[0]);
-                $count  = count($fields);
-                $key1   = array_shift($fields);
-                $key2   = $fields ? array_shift($fields) : '';
-                $key    = $key ?: $key1;
-
-                if (strpos($key, '.')) {
-                    list($alias, $key) = explode('.', $key);
-                }
-
-                if (3 == $count) {
-                    $column = $key2;
-                } elseif ($count < 3) {
-                    $column = $key1;
-                } else {
-                    $column = null;
-                }
-
-                $result = array_column($resultSet, $column, $key);
-            } else {
-                $result = [];
-            }
-        }
-
-        if (isset($cache) && isset($guid)) {
-            // 缓存数据
-            $this->cacheData($guid, $result, $cache);
-        }
-
-        return $result;
-    }
-
-    /**
      * SQL性能分析
      * @access protected
      * @param  string $sql

+ 1 - 1
thinkphp/library/think/facade/Route.php

@@ -26,7 +26,7 @@ use think\Facade;
  * @method void setName(string $name) static 批量导入路由标识
  * @method void import(array $rules, string $type = '*') static 导入配置文件的路由规则
  * @method \think\route\RuleItem rule(string $rule, mixed $route, string $method = '*', array $option = [], array $pattern = []) static 注册路由规则
- * @method void rules(array $rules, string $method = '*', array $option = [], array $pattern = []) static 批量注册路由规则
+ * @method void rules(string $rules, string $method = '*', array $option = [], array $pattern = []) static 批量注册路由规则
  * @method \think\route\RuleGroup group(string|array $name, mixed $route, string $method = '*', array $option = [], array $pattern = []) static 注册路由分组
  * @method \think\route\RuleItem any(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册路由
  * @method \think\route\RuleItem get(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册路由

+ 1 - 1
thinkphp/library/think/log/driver/File.php

@@ -72,7 +72,7 @@ class File
                 $info[$type][] = $this->config['json'] ? $msg : '[ ' . $type . ' ] ' . $msg;
             }
 
-            if (!$this->config['json'] && (true === $this->config['apart_level'] || in_array($type, $this->config['apart_level']))) {
+            if (!$this->config['json'] && in_array($type, $this->config['apart_level'])) {
                 // 独立记录的日志级别
                 $filename = $this->getApartLevelFile($path, $type);
 

+ 0 - 6
thinkphp/library/think/model/concern/Attribute.php

@@ -37,12 +37,6 @@ trait Attribute
     protected $json = [];
 
     /**
-     * JSON数据取出是否需要转换为数组
-     * @var bool
-     */
-    protected $jsonAssoc = false;
-
-    /**
      * JSON数据表字段类型
      * @var array
      */

+ 2 - 20
thinkphp/library/think/model/concern/SoftDelete.php

@@ -11,12 +11,6 @@ trait SoftDelete
 {
 
     /**
-     * 是否包含软删除数据
-     * @var bool
-     */
-    protected $withTrashed = false;
-
-    /**
      * 判断当前实例是否被软删除
      * @access public
      * @return boolean
@@ -41,19 +35,7 @@ trait SoftDelete
     {
         $model = new static();
 
-        return $model->withTrashedData(true)->db(false);
-    }
-
-    /**
-     * 是否包含软删除数据
-     * @access protected
-     * @param  bool $withTrashed 是否包含软删除数据
-     * @return $this
-     */
-    protected function withTrashedData($withTrashed)
-    {
-        $this->withTrashed = $withTrashed;
-        return $this;
+        return $model->db(false);
     }
 
     /**
@@ -105,7 +87,7 @@ trait SoftDelete
 
             $result = $this->isUpdate()->withEvent(false)->save();
 
-            $this->withEvent(true);
+            $this->withEvent = true;
         } else {
             // 读取更新条件
             $where = $this->getWhere();

+ 1 - 1
thinkphp/library/think/model/relation/BelongsToMany.php

@@ -563,7 +563,7 @@ class BelongsToMany extends Relation
         $pivot[] = [$this->localKey, '=', $this->parent->$pk];
 
         if (isset($id)) {
-            $pivot[] = [$this->foreignKey, is_array($id) ? 'in' : '=', $id];
+            $pivot[] = is_array($id) ? [$this->foreignKey, 'in', $id] : [$this->foreignKey, '=', $id];
         }
 
         $result = $this->pivot->where($pivot)->delete();

+ 3 - 3
thinkphp/library/think/model/relation/MorphTo.php

@@ -198,14 +198,14 @@ class MorphTo extends Relation
                     if ($key == $result->$morphType) {
                         // 关联模型
                         if (!isset($data[$result->$morphKey])) {
-                            $relationModel = null;
+                            throw new Exception('relation data not exists :' . $this->model);
                         } else {
                             $relationModel = $data[$result->$morphKey];
                             $relationModel->setParent(clone $result);
                             $relationModel->isUpdate(true);
-                        }
 
-                        $result->setRelation($attr, $relationModel);
+                            $result->setRelation($attr, $relationModel);
+                        }
                     }
                 }
             }

+ 1 - 23
thinkphp/library/think/route/Dispatch.php

@@ -162,29 +162,7 @@ abstract class Dispatch
             $this->autoValidate($option['validate']);
         }
 
-        $data = $this->exec();
-
-        return $this->autoResponse($data);
-    }
-
-    protected function autoResponse($data)
-    {
-        if ($data instanceof Response) {
-            $response = $data;
-        } elseif (!is_null($data)) {
-            // 默认自动识别响应输出类型
-            $isAjax = $this->request->isAjax();
-            $type   = $isAjax ? $this->rule->getConfig('default_ajax_return') : $this->rule->getConfig('default_return_type');
-
-            $response = Response::create($data, $type);
-        } else {
-            $data     = ob_get_clean();
-            $data     = false === $data ? '' : $data;
-            $status   = '' === $data ? 204 : 200;
-            $response = Response::create($data, '', $status);
-        }
-
-        return $response;
+        return $this->exec();
     }
 
     /**

+ 0 - 10
thinkphp/library/think/route/Rule.php

@@ -172,16 +172,6 @@ abstract class Rule
     }
 
     /**
-     * 获取路由所在域名
-     * @access public
-     * @return string
-     */
-    public function getDomain()
-    {
-        return $this->parent->getDomain();
-    }
-
-    /**
      * 获取变量规则定义
      * @access public
      * @param  string  $name 变量名

+ 18 - 40
thinkphp/library/think/route/RuleGroup.php

@@ -312,50 +312,33 @@ class RuleGroup extends Rule
             }
         }
 
-        if (empty($regex)) {
-            return false;
-        }
-
         try {
-            $result = preg_match('/^(?:' . implode('|', $regex) . ')/u', $url, $match);
-        } catch (\Exception $e) {
-            throw new Exception('route pattern error');
-        }
+            if (!empty($regex) && preg_match('/^(?:' . implode('|', $regex) . ')/u', $url, $match)) {
+                $var = [];
+                foreach ($match as $key => $val) {
+                    if (is_string($key) && '' !== $val) {
+                        list($name, $pos) = explode('_THINK_', $key);
 
-        if ($result) {
-            $var = [];
-            foreach ($match as $key => $val) {
-                if (is_string($key) && '' !== $val) {
-                    list($name, $pos) = explode('_THINK_', $key);
-
-                    $var[$name] = $val;
-                }
-            }
-
-            if (!isset($pos)) {
-                foreach ($regex as $key => $item) {
-                    if (0 === strpos(str_replace(['\/', '\-', '\\' . $depr], ['/', '-', $depr], $item), $match[0])) {
-                        $pos = $key;
-                        break;
+                        $var[$name] = $val;
                     }
                 }
-            }
 
-            $rule  = $items[$pos]->getRule();
-            $array = $this->router->getRule($rule);
-
-            foreach ($array as $item) {
-                if (in_array($item->getMethod(), ['*', strtolower($request->method())])) {
-                    $result = $item->checkRule($request, $url, $var);
-
-                    if (false !== $result) {
-                        return $result;
+                if (!isset($pos)) {
+                    foreach ($regex as $key => $item) {
+                        if (0 === strpos(str_replace(['\/', '\-', '\\' . $depr], ['/', '-', $depr], $item), $match[0])) {
+                            $pos = $key;
+                            break;
+                        }
                     }
                 }
+
+                return $items[$pos]->checkRule($request, $url, $var);
             }
-        }
 
-        return false;
+            return false;
+        } catch (\Exception $e) {
+            throw new Exception('route pattern error');
+        }
     }
 
     /**
@@ -431,11 +414,6 @@ class RuleGroup extends Rule
 
         $method = strtolower($method);
 
-        if ('/' === $rule || '' === $rule) {
-            // 首页自动完整匹配
-            $rule .= '$';
-        }
-
         // 创建路由规则实例
         $ruleItem = new RuleItem($this->router, $this, $name, $rule, $route, $method, $option, $pattern);
 

+ 1 - 2
thinkphp/library/think/route/RuleItem.php

@@ -128,7 +128,6 @@ class RuleItem extends Rule
             $value = [$this->rule, $vars, $this->parent->getDomain(), $suffix, $this->method];
 
             Container::get('rule_name')->set($name, $value, $first);
-            Container::get('rule_name')->setRule($this->rule, $this);
         }
     }
 
@@ -243,7 +242,7 @@ class RuleItem extends Rule
         }
 
         if (false === strpos($rule, '<')) {
-            if (0 === strcasecmp($rule, $url) || (!$completeMatch && 0 === strncasecmp($rule . $depr, $url . $depr, strlen($rule . $depr)))) {
+            if (0 === strcasecmp($rule, $url) || (!$completeMatch && 0 === strncasecmp($rule, $url, strlen($rule)))) {
                 return $var;
             }
             return false;

+ 0 - 57
thinkphp/library/think/route/RuleName.php

@@ -14,7 +14,6 @@ namespace think\route;
 class RuleName
 {
     protected $item = [];
-    protected $rule = [];
 
     /**
      * 注册路由标识
@@ -34,62 +33,6 @@ class RuleName
     }
 
     /**
-     * 注册路由规则
-     * @access public
-     * @param  string   $rule      路由规则
-     * @param  RuleItem $route     路由
-     * @return void
-     */
-    public function setRule($rule, $route)
-    {
-        $this->rule[$route->getDomain()][$rule][$route->getRoute()] = $route;
-    }
-
-    /**
-     * 根据路由规则获取路由对象(列表)
-     * @access public
-     * @param  string   $name      路由标识
-     * @param  string   $domain   域名
-     * @return array
-     */
-    public function getRule($rule, $domain = null)
-    {
-        return isset($this->rule[$domain][$rule]) ? $this->rule[$domain][$rule] : [];
-    }
-
-    /**
-     * 获取全部路由列表
-     * @access public
-     * @param  string   $domain   域名
-     * @return array
-     */
-    public function getRuleList($domain = null)
-    {
-        $list = [];
-
-        foreach ($this->rule as $ruleDomain => $rules) {
-            foreach ($rules as $rule => $items) {
-                foreach ($items as $item) {
-                    $val = [];
-
-                    foreach (['method', 'rule', 'name', 'route', 'pattern', 'option'] as $param) {
-                        $call        = 'get' . $param;
-                        $val[$param] = $item->$call();
-                    }
-
-                    $list[$ruleDomain][] = $val;
-                }
-            }
-        }
-
-        if ($domain) {
-            return isset($list[$domain]) ? $list[$domain] : [];
-        }
-
-        return $list;
-    }
-
-    /**
      * 导入路由标识
      * @access public
      * @param  array   $name      路由标识

+ 30 - 37
thinkphp/library/think/route/dispatch/Module.php

@@ -15,7 +15,6 @@ use ReflectionMethod;
 use think\exception\ClassNotFoundException;
 use think\exception\HttpException;
 use think\Loader;
-use think\Request;
 use think\route\Dispatch;
 
 class Module extends Dispatch
@@ -85,8 +84,8 @@ class Module extends Dispatch
         // 监听module_init
         $this->app['hook']->listen('module_init');
 
+        // 实例化控制器
         try {
-            // 实例化控制器
             $instance = $this->app->controller($this->controller,
                 $this->rule->getConfig('url_controller_layer'),
                 $this->rule->getConfig('controller_suffix'),
@@ -95,42 +94,36 @@ class Module extends Dispatch
             throw new HttpException(404, 'controller not exists:' . $e->getClass());
         }
 
-        $this->app['middleware']->controller(function (Request $request, $next) use ($instance) {
-            // 获取当前操作名
-            $action = $this->actionName . $this->rule->getConfig('action_suffix');
-
-            if (is_callable([$instance, $action])) {
-                // 执行操作方法
-                $call = [$instance, $action];
-
-                // 严格获取当前操作方法名
-                $reflect    = new ReflectionMethod($instance, $action);
-                $methodName = $reflect->getName();
-                $suffix     = $this->rule->getConfig('action_suffix');
-                $actionName = $suffix ? substr($methodName, 0, -strlen($suffix)) : $methodName;
-                $this->request->setAction($actionName);
-
-                // 自动获取请求变量
-                $vars = $this->rule->getConfig('url_param_type')
-                ? $this->request->route()
-                : $this->request->param();
-            } elseif (is_callable([$instance, '_empty'])) {
-                // 空操作
-                $call    = [$instance, '_empty'];
-                $vars    = [$this->actionName];
-                $reflect = new ReflectionMethod($instance, '_empty');
-            } else {
-                // 操作不存在
-                throw new HttpException(404, 'method not exists:' . get_class($instance) . '->' . $action . '()');
-            }
-
-            $this->app['hook']->listen('action_begin', $call);
-
-            $data = $this->app->invokeReflectMethod($instance, $reflect, $vars);
+        // 获取当前操作名
+        $action = $this->actionName . $this->rule->getConfig('action_suffix');
+
+        if (is_callable([$instance, $action])) {
+            // 执行操作方法
+            $call = [$instance, $action];
+
+            // 严格获取当前操作方法名
+            $reflect    = new ReflectionMethod($instance, $action);
+            $methodName = $reflect->getName();
+            $suffix     = $this->rule->getConfig('action_suffix');
+            $actionName = $suffix ? substr($methodName, 0, -strlen($suffix)) : $methodName;
+            $this->request->setAction($actionName);
+
+            // 自动获取请求变量
+            $vars = $this->rule->getConfig('url_param_type')
+            ? $this->request->route()
+            : $this->request->param();
+        } elseif (is_callable([$instance, '_empty'])) {
+            // 空操作
+            $call    = [$instance, '_empty'];
+            $vars    = [$this->actionName];
+            $reflect = new ReflectionMethod($instance, '_empty');
+        } else {
+            // 操作不存在
+            throw new HttpException(404, 'method not exists:' . get_class($instance) . '->' . $action . '()');
+        }
 
-            return $this->autoResponse($data);
-        });
+        $this->app['hook']->listen('action_begin', $call);
 
-        return $this->app['middleware']->dispatch($this->request, 'controller');
+        return $this->app->invokeReflectMethod($instance, $reflect, $vars);
     }
 }

+ 1 - 1
thinkphp/tpl/default_index.tpl

@@ -5,6 +5,6 @@ class Index{$suffix}
 {
     public function index()
     {
-        return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V5.1<br/><span style="font-size:30px">12载初心不改(2006-2018) - 你值得信赖的PHP框架</span></p></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="eab4b9f840753f8e7"></think>';
+        return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) 2018新年快乐</h1><p> ThinkPHP V5.1<br/><span style="font-size:30px">12载初心不改(2006-2018) - 你值得信赖的PHP框架</span></p></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="eab4b9f840753f8e7"></think>';
     }
 }

+ 1 - 1
vendor/autoload.php

@@ -4,4 +4,4 @@
 
 require_once __DIR__ . '/composer/autoload_real.php';
 
-return ComposerAutoloaderInite4d934b72787b3b727ab4a05592fe341::getLoader();
+return ComposerAutoloaderInit0402c38ddd8eba428c182633170c04fe::getLoader();

+ 7 - 7
vendor/composer/autoload_real.php

@@ -2,7 +2,7 @@
 
 // autoload_real.php @generated by Composer
 
-class ComposerAutoloaderInite4d934b72787b3b727ab4a05592fe341
+class ComposerAutoloaderInit0402c38ddd8eba428c182633170c04fe
 {
     private static $loader;
 
@@ -19,15 +19,15 @@ class ComposerAutoloaderInite4d934b72787b3b727ab4a05592fe341
             return self::$loader;
         }
 
-        spl_autoload_register(array('ComposerAutoloaderInite4d934b72787b3b727ab4a05592fe341', 'loadClassLoader'), true, true);
+        spl_autoload_register(array('ComposerAutoloaderInit0402c38ddd8eba428c182633170c04fe', 'loadClassLoader'), true, true);
         self::$loader = $loader = new \Composer\Autoload\ClassLoader();
-        spl_autoload_unregister(array('ComposerAutoloaderInite4d934b72787b3b727ab4a05592fe341', 'loadClassLoader'));
+        spl_autoload_unregister(array('ComposerAutoloaderInit0402c38ddd8eba428c182633170c04fe', 'loadClassLoader'));
 
         $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
         if ($useStaticLoader) {
             require_once __DIR__ . '/autoload_static.php';
 
-            call_user_func(\Composer\Autoload\ComposerStaticInite4d934b72787b3b727ab4a05592fe341::getInitializer($loader));
+            call_user_func(\Composer\Autoload\ComposerStaticInit0402c38ddd8eba428c182633170c04fe::getInitializer($loader));
         } else {
             $map = require __DIR__ . '/autoload_namespaces.php';
             foreach ($map as $namespace => $path) {
@@ -48,19 +48,19 @@ class ComposerAutoloaderInite4d934b72787b3b727ab4a05592fe341
         $loader->register(true);
 
         if ($useStaticLoader) {
-            $includeFiles = Composer\Autoload\ComposerStaticInite4d934b72787b3b727ab4a05592fe341::$files;
+            $includeFiles = Composer\Autoload\ComposerStaticInit0402c38ddd8eba428c182633170c04fe::$files;
         } else {
             $includeFiles = require __DIR__ . '/autoload_files.php';
         }
         foreach ($includeFiles as $fileIdentifier => $file) {
-            composerRequiree4d934b72787b3b727ab4a05592fe341($fileIdentifier, $file);
+            composerRequire0402c38ddd8eba428c182633170c04fe($fileIdentifier, $file);
         }
 
         return $loader;
     }
 }
 
-function composerRequiree4d934b72787b3b727ab4a05592fe341($fileIdentifier, $file)
+function composerRequire0402c38ddd8eba428c182633170c04fe($fileIdentifier, $file)
 {
     if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
         require $file;

+ 4 - 4
vendor/composer/autoload_static.php

@@ -4,7 +4,7 @@
 
 namespace Composer\Autoload;
 
-class ComposerStaticInite4d934b72787b3b727ab4a05592fe341
+class ComposerStaticInit0402c38ddd8eba428c182633170c04fe
 {
     public static $files = array (
         '1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php',
@@ -303,9 +303,9 @@ class ComposerStaticInite4d934b72787b3b727ab4a05592fe341
     public static function getInitializer(ClassLoader $loader)
     {
         return \Closure::bind(function () use ($loader) {
-            $loader->prefixLengthsPsr4 = ComposerStaticInite4d934b72787b3b727ab4a05592fe341::$prefixLengthsPsr4;
-            $loader->prefixDirsPsr4 = ComposerStaticInite4d934b72787b3b727ab4a05592fe341::$prefixDirsPsr4;
-            $loader->classMap = ComposerStaticInite4d934b72787b3b727ab4a05592fe341::$classMap;
+            $loader->prefixLengthsPsr4 = ComposerStaticInit0402c38ddd8eba428c182633170c04fe::$prefixLengthsPsr4;
+            $loader->prefixDirsPsr4 = ComposerStaticInit0402c38ddd8eba428c182633170c04fe::$prefixDirsPsr4;
+            $loader->classMap = ComposerStaticInit0402c38ddd8eba428c182633170c04fe::$classMap;
 
         }, null, ClassLoader::class);
     }

+ 6 - 6
vendor/composer/installed.json

@@ -191,17 +191,17 @@
     },
     {
         "name": "topthink/framework",
-        "version": "v5.1.17",
-        "version_normalized": "5.1.17.0",
+        "version": "v5.1.16",
+        "version_normalized": "5.1.16.0",
         "source": {
             "type": "git",
             "url": "https://github.com/top-think/framework.git",
-            "reference": "b851761979a219c92285fee691030aca50bcb5bc"
+            "reference": "e0a8bdc52957a8f9774353fbfa0b9fd6ee206188"
         },
         "dist": {
             "type": "zip",
-            "url": "https://files.phpcomposer.com/files/top-think/framework/b851761979a219c92285fee691030aca50bcb5bc.zip",
-            "reference": "b851761979a219c92285fee691030aca50bcb5bc",
+            "url": "https://files.phpcomposer.com/files/top-think/framework/e0a8bdc52957a8f9774353fbfa0b9fd6ee206188.zip",
+            "reference": "e0a8bdc52957a8f9774353fbfa0b9fd6ee206188",
             "shasum": ""
         },
         "require": {
@@ -217,7 +217,7 @@
             "sebastian/phpcpd": "2.*",
             "squizlabs/php_codesniffer": "2.*"
         },
-        "time": "2018-06-17T14:11:40+00:00",
+        "time": "2018-06-08T04:10:59+00:00",
         "type": "think-framework",
         "installation-source": "dist",
         "notification-url": "https://packagist.org/downloads/",