From 77306720d5cbdf0fa97be9dea102a373a401f422 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 8 Oct 2018 21:18:23 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E6=94=B9=E8=BF=9BparseOrder=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ThinkPHP/Library/Think/Db/Driver.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ThinkPHP/Library/Think/Db/Driver.class.php b/ThinkPHP/Library/Think/Db/Driver.class.php index 66361ffc1..1a673991e 100644 --- a/ThinkPHP/Library/Think/Db/Driver.class.php +++ b/ThinkPHP/Library/Think/Db/Driver.class.php @@ -761,7 +761,7 @@ protected function parseOrder($order) if (is_array($order)) { foreach ($order as $key => $val) { if (is_numeric($key)) { - if (false === strpos($val, '(')) { + if (false === strpos($val, '(') && false === strpos($val, ';')) { $array[] = $this->parseKey($val); } } elseif (false === strpos($key, ')') && false === strpos($key, '#')) { @@ -776,7 +776,7 @@ protected function parseOrder($order) foreach (explode(',', $order) as $val) { if (preg_match('/\s+(ASC|DESC)$/i', rtrim($val), $match, PREG_OFFSET_CAPTURE)) { $array[] = $this->parseKey(ltrim(substr($val, 0, $match[0][1]))) . ' ' . $match[1][0]; - } elseif (false === strpos($val, '(')) { + } elseif (false === strpos($val, '(') && false === strpos($val, ';')) { $array[] = $this->parseKey($val); } } From 9748cb80d2f24c89218f358ca2f5ab88ee33396f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 8 Oct 2018 21:54:51 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ThinkPHP/Library/Think/Db/Driver.class.php | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ThinkPHP/Library/Think/Db/Driver.class.php b/ThinkPHP/Library/Think/Db/Driver.class.php index 1a673991e..a3b128318 100644 --- a/ThinkPHP/Library/Think/Db/Driver.class.php +++ b/ThinkPHP/Library/Think/Db/Driver.class.php @@ -758,29 +758,29 @@ protected function parseOrder($order) return ''; } $array = array(); + if (is_string($order) && '[RAND]' != $order) { + $order = explode(',', $order); + } + if (is_array($order)) { foreach ($order as $key => $val) { if (is_numeric($key)) { - if (false === strpos($val, '(') && false === strpos($val, ';')) { - $array[] = $this->parseKey($val); - } - } elseif (false === strpos($key, ')') && false === strpos($key, '#')) { - $sort = in_array(strtolower($val), array('asc', 'desc')) ? ' ' . $val : ''; + list($key, $sort) = explode(' ', strpos($val, ' ') ? $val : $val . ' '); + } else { + $sort = $val; + } + + if (preg_match('/^[\w]+$/', $key)) { + $sort = strtoupper($sort); + $sort = in_array($sort, ['ASC', 'DESC'], true) ? ' ' . $sort : ''; $array[] = $this->parseKey($key, true) . $sort; } } } elseif ('[RAND]' == $order) { // 随机排序 $array[] = $this->parseRand(); - } else { - foreach (explode(',', $order) as $val) { - if (preg_match('/\s+(ASC|DESC)$/i', rtrim($val), $match, PREG_OFFSET_CAPTURE)) { - $array[] = $this->parseKey(ltrim(substr($val, 0, $match[0][1]))) . ' ' . $match[1][0]; - } elseif (false === strpos($val, '(') && false === strpos($val, ';')) { - $array[] = $this->parseKey($val); - } - } } + $order = implode(',', $array); return !empty($order) ? ' ORDER BY ' . $order : ''; } From 912ac4430244469964a852ee8f360b96208f6470 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 11 Oct 2018 10:19:34 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ThinkPHP/Library/Think/Db/Driver.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ThinkPHP/Library/Think/Db/Driver.class.php b/ThinkPHP/Library/Think/Db/Driver.class.php index a3b128318..a27e3972d 100644 --- a/ThinkPHP/Library/Think/Db/Driver.class.php +++ b/ThinkPHP/Library/Think/Db/Driver.class.php @@ -770,7 +770,7 @@ protected function parseOrder($order) $sort = $val; } - if (preg_match('/^[\w]+$/', $key)) { + if (preg_match('/^[\w\.]+$/', $key)) { $sort = strtoupper($sort); $sort = in_array($sort, ['ASC', 'DESC'], true) ? ' ' . $sort : ''; $array[] = $this->parseKey($key, true) . $sort; From eca555ea883fa7f936c4b284f56d9778bf27e588 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 16 Oct 2018 11:00:06 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E6=94=B9=E8=BF=9Border=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2=E7=A9=BA=E6=A0=BC=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ThinkPHP/Library/Think/Db/Driver.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ThinkPHP/Library/Think/Db/Driver.class.php b/ThinkPHP/Library/Think/Db/Driver.class.php index a27e3972d..13c3d7d06 100644 --- a/ThinkPHP/Library/Think/Db/Driver.class.php +++ b/ThinkPHP/Library/Think/Db/Driver.class.php @@ -759,7 +759,7 @@ protected function parseOrder($order) } $array = array(); if (is_string($order) && '[RAND]' != $order) { - $order = explode(',', $order); + $order = array_map('trim', explode(',', $order)); } if (is_array($order)) { From 43d3d95d2704a210d831ad65083394dbaaefbdd8 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 18 Oct 2018 18:17:50 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=81=9A=E5=90=88?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=AE=89=E5=85=A8=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ThinkPHP/Library/Think/Db/Driver.class.php | 4 ++-- ThinkPHP/Library/Think/Db/Driver/Mysql.class.php | 9 +++++++-- ThinkPHP/Library/Think/Db/Driver/Sqlsrv.class.php | 9 +++++++-- ThinkPHP/Library/Think/Model.class.php | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ThinkPHP/Library/Think/Db/Driver.class.php b/ThinkPHP/Library/Think/Db/Driver.class.php index 13c3d7d06..f01fc6a12 100644 --- a/ThinkPHP/Library/Think/Db/Driver.class.php +++ b/ThinkPHP/Library/Think/Db/Driver.class.php @@ -448,12 +448,12 @@ protected function bindParam($name, $value) /** * 字段和表名处理 - * @access protected + * @access public * @param string $key * @param bool $strict * @return string */ - protected function parseKey($key, $strict = false) + public function parseKey($key, $strict = false) { return $key; } diff --git a/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php b/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php index dbece8879..2a289e5bd 100644 --- a/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php +++ b/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php @@ -94,14 +94,19 @@ public function getTables($dbName = '') /** * 字段和表名处理 - * @access protected + * @access public * @param string $key * @param bool $strict * @return string */ - protected function parseKey($key, $strict = false) + public function parseKey($key, $strict = false) { $key = trim($key); + + if ($strict && !preg_match('/^[\w\.\*]+$/', $key)) { + E('not support data:' . $key); + } + if ($strict || (!is_numeric($key) && !preg_match('/[,\'\"\*\(\)`.\s]/', $key))) { $key = '`' . $key . '`'; } diff --git a/ThinkPHP/Library/Think/Db/Driver/Sqlsrv.class.php b/ThinkPHP/Library/Think/Db/Driver/Sqlsrv.class.php index cff986ddb..5d4e52cdc 100644 --- a/ThinkPHP/Library/Think/Db/Driver/Sqlsrv.class.php +++ b/ThinkPHP/Library/Think/Db/Driver/Sqlsrv.class.php @@ -105,14 +105,19 @@ protected function parseOrder($order) /** * 字段和表名处理 - * @access protected + * @access public * @param string $key * @param bool $strict * @return string */ - protected function parseKey($key, $strict = false) + public function parseKey($key, $strict = false) { $key = trim($key); + + if ($strict && !preg_match('/^[\w\.\*]+$/', $key)) { + E('not support data:' . $key); + } + if ($strict || (!is_numeric($key) && !preg_match('/[,\'\"\*\(\)\[.\s]/', $key))) { $key = '[' . $key . ']'; } diff --git a/ThinkPHP/Library/Think/Model.class.php b/ThinkPHP/Library/Think/Model.class.php index 275b00d8b..c1c6ebbd6 100644 --- a/ThinkPHP/Library/Think/Model.class.php +++ b/ThinkPHP/Library/Think/Model.class.php @@ -239,7 +239,7 @@ public function __call($method, $args) } elseif (in_array(strtolower($method), array('count', 'sum', 'min', 'max', 'avg'), true)) { // 统计查询的实现 $field = isset($args[0]) ? $args[0] : '*'; - return $this->getField(strtoupper($method) . '(' . $field . ') AS tp_' . $method); + return $this->getField(strtoupper($method) . '(' . $this->db->parseKey($field, true) . ') AS tp_' . $method); } elseif (strtolower(substr($method, 0, 5)) == 'getby') { // 根据某个字段获取记录 $field = parse_name(substr($method, 5)); From 45489acfa131cf47efa61e85be05bedc8c3c94cf Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 21 Oct 2018 16:26:55 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E8=81=9A=E5=90=88=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=AE=89=E5=85=A8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ThinkPHP/ThinkPHP.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ThinkPHP/ThinkPHP.php b/ThinkPHP/ThinkPHP.php index 9825594f4..6e165683a 100644 --- a/ThinkPHP/ThinkPHP.php +++ b/ThinkPHP/ThinkPHP.php @@ -22,7 +22,7 @@ } // 版本信息 -const THINK_VERSION = '3.2.4'; +const THINK_VERSION = '3.2.5'; // URL 模式定义 const URL_COMMON = 0; //普通模式 From 6c532977a4a69249ee32dc14b9fef45083799976 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 21 Oct 2018 16:33:32 +0800 Subject: [PATCH 07/14] =?UTF-8?q?readme=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 00a1fa42b..5cd6d1597 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -**3.2版本已经过了维护生命周期,官方已经不再维护,请及时更新至5.0版本** +**3.2版本已经过了维护生命周期,官方已经不再维护,请及时更新至5.0或者5.1版本** ## 简介 From d615b60fd8e1d96ae6be1500bb8baf8438eea47d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 30 Oct 2018 15:18:30 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E6=94=B9=E8=BF=9BparseOrder=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=AF=B9=E5=88=AB=E5=90=8D=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ThinkPHP/Library/Think/Db/Driver.class.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ThinkPHP/Library/Think/Db/Driver.class.php b/ThinkPHP/Library/Think/Db/Driver.class.php index f01fc6a12..5de8f5c84 100644 --- a/ThinkPHP/Library/Think/Db/Driver.class.php +++ b/ThinkPHP/Library/Think/Db/Driver.class.php @@ -771,9 +771,14 @@ protected function parseOrder($order) } if (preg_match('/^[\w\.]+$/', $key)) { - $sort = strtoupper($sort); - $sort = in_array($sort, ['ASC', 'DESC'], true) ? ' ' . $sort : ''; - $array[] = $this->parseKey($key, true) . $sort; + $sort = strtoupper($sort); + $sort = in_array($sort, ['ASC', 'DESC'], true) ? ' ' . $sort : ''; + if (strpos($key, '.')) { + list($alais, $key) = explode('.', $key); + $array[] = $this->parseKey($alias, true) . '.' . $this->parseKey($key, true) . $sort; + } else { + $array[] = $this->parseKey($key, true) . $sort; + } } } } elseif ('[RAND]' == $order) { From e9d317d891dbdd2df461e2bce61f334f8dc1eda0 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 30 Oct 2018 16:03:08 +0800 Subject: [PATCH 09/14] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ThinkPHP/Library/Think/Db/Driver.class.php | 2 +- ThinkPHP/Library/Think/Db/Driver/Mysql.class.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ThinkPHP/Library/Think/Db/Driver.class.php b/ThinkPHP/Library/Think/Db/Driver.class.php index 5de8f5c84..a5048fe8f 100644 --- a/ThinkPHP/Library/Think/Db/Driver.class.php +++ b/ThinkPHP/Library/Think/Db/Driver.class.php @@ -774,7 +774,7 @@ protected function parseOrder($order) $sort = strtoupper($sort); $sort = in_array($sort, ['ASC', 'DESC'], true) ? ' ' . $sort : ''; if (strpos($key, '.')) { - list($alais, $key) = explode('.', $key); + list($alias, $key) = explode('.', $key); $array[] = $this->parseKey($alias, true) . '.' . $this->parseKey($key, true) . $sort; } else { $array[] = $this->parseKey($key, true) . $sort; diff --git a/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php b/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php index 2a289e5bd..e67575385 100644 --- a/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php +++ b/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php @@ -101,13 +101,17 @@ public function getTables($dbName = '') */ public function parseKey($key, $strict = false) { + if (is_int($key)) { + return $key; + } + $key = trim($key); if ($strict && !preg_match('/^[\w\.\*]+$/', $key)) { E('not support data:' . $key); } - if ($strict || (!is_numeric($key) && !preg_match('/[,\'\"\*\(\)`.\s]/', $key))) { + if ('*' != $key && !preg_match('/[,\'\"\*\(\)`.\s]/', $key)) { $key = '`' . $key . '`'; } return $key; From 28e3172513a56b182b0109778ec51d5abd2c26dd Mon Sep 17 00:00:00 2001 From: Zhu Ming Date: Mon, 19 Nov 2018 01:35:08 +0800 Subject: [PATCH 10/14] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 严格检查`checkUrlMatch(...)`返回值为`false`才表示动态路由未匹配成功 --- ThinkPHP/Library/Think/Route.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ThinkPHP/Library/Think/Route.class.php b/ThinkPHP/Library/Think/Route.class.php index 5349dbffd..bb7ae3473 100644 --- a/ThinkPHP/Library/Think/Route.class.php +++ b/ThinkPHP/Library/Think/Route.class.php @@ -58,7 +58,8 @@ public static function check($paths = array()) continue; } } - if ($matches = self::checkUrlMatch($rule, $args, $regx)) { + $matches = self::checkUrlMatch($rule, $args, $regx); + if ($matches !== false) { if ($route[0] instanceof \Closure) { // 执行闭包 $result = self::invoke($route[0], $matches); From a0ccff933ece5b09ac3f324764957e847af5de83 Mon Sep 17 00:00:00 2001 From: Zhu Ming Date: Mon, 19 Nov 2018 01:37:47 +0800 Subject: [PATCH 11/14] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `ruleCache(...)`中读取路由配置应当避免改变路由定义顺序,因为顺序也会影响路由的解析 --- ThinkPHP/Library/Think/Route.class.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ThinkPHP/Library/Think/Route.class.php b/ThinkPHP/Library/Think/Route.class.php index bb7ae3473..478a479e1 100644 --- a/ThinkPHP/Library/Think/Route.class.php +++ b/ThinkPHP/Library/Think/Route.class.php @@ -272,9 +272,10 @@ public static function ruleCache($update = false) } } // 动态路由 - $result[1] = C('URL_ROUTE_RULES'); - if (!empty($result[1])) { - foreach ($result[1] as $rule => $route) { + $result[1] = []; + $dynamicRoutes = C('URL_ROUTE_RULES'); + if (!empty($dynamicRoutes)) { + foreach ($dynamicRoutes as $rule => $route) { if (!is_array($route)) { $route = array($route); } elseif (is_numeric($rule)) { @@ -348,8 +349,6 @@ public static function ruleCache($update = false) } $route[] = $args; $result[1][$rule] = $route; - } else { - unset($result[1][$rule]); } } } From d347b49d7c18bfbbed8b185e635539d2562778ce Mon Sep 17 00:00:00 2001 From: Zhu Ming Date: Mon, 19 Nov 2018 01:42:21 +0800 Subject: [PATCH 12/14] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 确保为数组之后才能当数组使用 --- ThinkPHP/Library/Think/Route.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ThinkPHP/Library/Think/Route.class.php b/ThinkPHP/Library/Think/Route.class.php index 478a479e1..bbe846a83 100644 --- a/ThinkPHP/Library/Think/Route.class.php +++ b/ThinkPHP/Library/Think/Route.class.php @@ -437,7 +437,7 @@ private static function checkUrlMatch(&$rule, &$args, &$regx) } } else { // 如果值在排除的名单里 - if (in_array($var, $val[2])) { + if (is_array($val[2]) && in_array($var, $val[2])) { return false; } } From 610001869c8ecb1027d885260fd6f95a86b7bd55 Mon Sep 17 00:00:00 2001 From: Zhu Ming Date: Tue, 20 Nov 2018 01:18:07 +0800 Subject: [PATCH 13/14] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 既然&$paths当做堆栈用,就不应该中途重置堆栈 --- ThinkPHP/Library/Think/Dispatcher.class.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ThinkPHP/Library/Think/Dispatcher.class.php b/ThinkPHP/Library/Think/Dispatcher.class.php index 8d8376b63..9ef34c342 100644 --- a/ThinkPHP/Library/Think/Dispatcher.class.php +++ b/ThinkPHP/Library/Think/Dispatcher.class.php @@ -76,7 +76,7 @@ public static function dispatch() $array = explode('/', $rule); // 模块绑定 define('BIND_MODULE', array_shift($array)); - // 控制器绑定 + // 控制器绑定 if (!empty($array)) { $controller = array_shift($array); if ($controller) { @@ -268,10 +268,6 @@ private static function getController(&$paths, $urlCase) if (defined('BIND_CONTROLLER')) { return BIND_CONTROLLER; } else { - if ($paths && C('URL_ROUTER_ON') && Route::check($paths)) { - $depr = C('URL_PATHINFO_DEPR'); - $paths = explode($depr, trim($_SERVER['PATH_INFO'], $depr)); - } if ($paths) { // PATH_INFO检测标签位 Hook::listen('path_info'); From 1a9f8ca15ed0febfada8a2c15a1cdcbcc9f14f18 Mon Sep 17 00:00:00 2001 From: Zhu Ming Date: Tue, 20 Nov 2018 01:31:25 +0800 Subject: [PATCH 14/14] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 用`ruleCache(...)`读取路由配置时,保持配置中路由定义的键的类型,以支持多个路由的路由表达式相同而路由参数不同的情况 - 在使用路由时,再处理键为索引的情况 --- ThinkPHP/Library/Think/Route.class.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/ThinkPHP/Library/Think/Route.class.php b/ThinkPHP/Library/Think/Route.class.php index bbe846a83..19b76213f 100644 --- a/ThinkPHP/Library/Think/Route.class.php +++ b/ThinkPHP/Library/Think/Route.class.php @@ -51,6 +51,10 @@ public static function check($paths = array()) // 动态路由检查 if (!empty($rules[1])) { foreach ($rules[1] as $rule => $route) { + if (is_numeric($rule)) { + $rule = array_shift($route); + } + $args = array_pop($route); if (isset($route[2])) { // 路由参数检查 @@ -147,6 +151,10 @@ public static function reverse($path, &$vars, $depr, $suffix = true) } if (isset($_rules[1][$path])) { foreach ($_rules[1][$path] as $rule => $route) { + if (is_numeric($rule)) { + $rule = array_shift($route); + } + $args = array_pop($route); $array = array(); if (isset($route[2])) { @@ -275,7 +283,10 @@ public static function ruleCache($update = false) $result[1] = []; $dynamicRoutes = C('URL_ROUTE_RULES'); if (!empty($dynamicRoutes)) { - foreach ($dynamicRoutes as $rule => $route) { + foreach ($dynamicRoutes as $key => $value) { + $rule = $key; + $route = $value; + if (!is_array($route)) { $route = array($route); } elseif (is_numeric($rule)) { @@ -348,6 +359,13 @@ public static function ruleCache($update = false) } } $route[] = $args; + + // 保持配置中路由定义的键的类型,以支持多个路由的路由表达式相同而路由参数不同的情况 + if (is_numeric($key)) { + array_unshift($route, $rule); + $rule = $key; + } + $result[1][$rule] = $route; } }