From 55763d0bf209c82bcad58000f3c22e670f862e92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=83=E5=BD=A9=E6=9E=AB=E5=8F=B6?= <424235748@qq.com> Date: Wed, 16 Aug 2023 09:07:43 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A3=80=E6=B5=8B=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E5=99=A8=E5=92=8C=E6=96=B9=E6=B3=95=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 七彩枫叶 <424235748@qq.com> --- app/admin/controller/system/Plugin.php | 27 +++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/app/admin/controller/system/Plugin.php b/app/admin/controller/system/Plugin.php index c4358973..dc5c594e 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); -- Gitee