优化方法检测判断

This commit is contained in:
Karson
2025-05-22 16:41:32 +08:00
parent e95df87aa1
commit a1a4c857bb

View File

@@ -521,19 +521,24 @@ class Request
// 获取原始请求类型 // 获取原始请求类型
return $this->server('REQUEST_METHOD') ?: 'GET'; return $this->server('REQUEST_METHOD') ?: 'GET';
} elseif (!$this->method) { } elseif (!$this->method) {
if (isset($_POST[Config::get('var_method')])) { $varMethod = Config::get('var_method');
$method = strtoupper($_POST[Config::get('var_method')]); if ($varMethod && isset($_POST[$varMethod])) {
$method = strtoupper($_POST[$varMethod]);
if (in_array($method, ['GET', 'POST', 'DELETE', 'PUT', 'PATCH'])) { if (in_array($method, ['GET', 'POST', 'DELETE', 'PUT', 'PATCH'])) {
$this->method = $method; $this->method = $method;
$this->{$this->method}($_POST); $this->{$this->method}($_POST);
} else { } else {
$this->method = 'POST'; $this->method = 'POST';
} }
unset($_POST[Config::get('var_method')]); unset($_POST[$varMethod]);
} elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
$this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
} else { } else {
$this->method = $this->server('REQUEST_METHOD') ?: 'GET'; $method = $this->server('REQUEST_METHOD') ?: 'GET';
$httpMethodOverride = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ?? '');
if ($method === 'POST' && in_array($httpMethodOverride, ['GET', 'POST', 'DELETE', 'PUT', 'PATCH'])) {
$this->method = $httpMethodOverride;
} else {
$this->method = $method;
}
} }
} }
return $this->method; return $this->method;