diff --git a/app/admin/controller/system/Plugin.php b/app/admin/controller/system/Plugin.php index c4358973d586e6a32418052fee94bd5a9a273a60..dc5c594e885e0b08a55da5e544a65bdf791952b2 100644 --- a/app/admin/controller/system/Plugin.php +++ b/app/admin/controller/system/Plugin.php @@ -309,15 +309,24 @@ class Plugin extends AdminController if (request()->isPost()) { $post['extends'] = input('extends'); $post['rewrite'] = input('rewrite'); - foreach ($post['rewrite'] as $kk => $vv) { - if ($kk[0] != '/') return $this->error('伪静态变量名称“' . $kk . '" 必须以“/”开头'); - $post['rewrite'][$kk] = str_replace('\\', '/', trim($vv, '/\\')); - $value = explode('/', $post['rewrite'][$kk]); - if (count($value) < 2) { - return $this->error('伪静态不符合规则'); - } - if (strtoupper($value[count($value) - 2][0]) !== $value[count($value) - 2][0]) { - return $this->error('控制器首字母必须大写'); + if($post['rewrite']) { + foreach ($post['rewrite'] as $key => $value){ + if (!str_starts_with($key, '/')) return $this->error('伪静态变量名称“' . $key . '" 必须以“/”开头'); + $value = explode('/', str_replace('\\', '/', trim($value, '/\\'))); + if (count($value) < 2) { + return $this->error("变量名称 {$key} 的 变量值中 伪静态不符合规则,变量值至少包含控制器和方法"); + } + $method = array_pop($value); + if (!class_exists('app\\index\\controller\\' . implode('\\', $value))) { + return $this->error("变量名称 {$key} 的 变量值中 控制器不存在,请再次检查确认"); + } + if (!method_exists('app\\index\\controller\\' . implode('\\', $value), $method)) { + return $this->error("变量名称 {$key} 的 变量值中 指定的方法在控制器中 {$method} 不存在,请再次检查确认"); + } + if (ucfirst(end($value)) != end($value)) { + return $this->error("变量名称 {$key} 的控制器首字母必须大写"); + } + $post["rewrite"][$key] = implode('/', $value).'/'.$method; } } $config = array_merge($config, $post);