取消 路由规则定义中的 \d 用法 使用变量规则替代 修正URL生成的一处可能的bug

This commit is contained in:
thinkphp
2016-01-11 19:09:17 +08:00
parent b337b1ad81
commit c4f2958231
2 changed files with 9 additions and 26 deletions

View File

@@ -217,8 +217,6 @@ class Route
}
if (!empty($rule)) {
// 子域名部署规则
// '子域名'=>'模块[/控制器/操作]'
// '子域名'=>'模块[/控制器/操作]?var1=a&var2=b&var3=*';
if ($rule instanceof \Closure) {
// 执行闭包
$reflect = new \ReflectionFunction($rule);
@@ -453,7 +451,7 @@ class Route
public static function parseUrl($url, $depr = '/')
{
if (isset(self::$bind['module'])) {
// 如果有模块/控制器绑定 针对路由到 模块/控制器 有效
// 如果有模块/控制器绑定
$url = self::$bind['module'] . '/' . $url;
}
// 分隔符替换 确保路由定义使用统一的分隔符
@@ -523,15 +521,7 @@ class Route
}
if (0 === strpos($val, ':')) {
// URL变量
if (strpos($val, '\\')) {
$type = substr($val, -1);
if ('d' == $type && !is_numeric($m1[$key])) {
return false;
}
$name = substr($val, 1, -2);
} else {
$name = substr($val, 1);
}
$name = substr($val, 1);
if (isset($m1[$key]) && isset($pattern[$name]) && !preg_match('/^' . $pattern[$name] . '$/', $m1[$key])) {
// 检查变量规则
return false;
@@ -561,11 +551,7 @@ class Route
$item = substr($item, 1, -1);
}
if (0 === strpos($item, ':')) {
if (strpos($item, '\\')) {
$var = substr($item, 1, -2);
} else {
$var = substr($item, 1);
}
$var = substr($item, 1);
$matches[$var] = array_shift($paths);
} else {
// 过滤URL中的静态变量

View File

@@ -30,8 +30,6 @@ class Url
if (is_string($vars)) {
// aaa=1&bbb=2 转换成数组
parse_str($vars, $vars);
} elseif (!is_array($vars)) {
$vars = [];
}
if (strpos($url, '?')) {
@@ -42,8 +40,8 @@ class Url
// 检测路由
if ($match = self::getRouteUrl($url, $vars)) {
// 处理路由规则中的特殊内容
$url = str_replace(['\\d', '$'], '', $match);
// 处理路由规则中的特殊字符
$url = str_replace('[--think--]', '', $match);
} else {
// 路由不存在 直接解析
$url = self::parseUrl($url);
@@ -161,11 +159,7 @@ class Url
}
if (0 === strpos($val, ':')) {
// URL变量
if (strpos($val, '\\')) {
$name = substr($val, 1, -2);
} else {
$name = substr($val, 1);
}
$name = substr($val, 1);
if (!$optional && !isset($vars[$name])) {
// 变量未设置
return false;
@@ -208,6 +202,9 @@ class Url
if (!empty($alias[$name])) {
foreach ($alias[$name] as $key => $url) {
// 检查变量匹配
if (strpos($url, '$')) {
$url = str_replace('$', '[--think--]', $url);
}
if (self::pattern($url, $vars, $check)) {
foreach ($vars as $key => $val) {
if (false !== strpos($url, '[:' . $key . ']')) {