Ignore case on plugin route method

This commit is contained in:
slawkens 2023-02-17 17:54:38 +01:00
parent 937af536b6
commit 6785ecad1d
2 changed files with 14 additions and 1 deletions

View File

@ -66,7 +66,8 @@ class Plugins {
if ($method !== '*') { if ($method !== '*') {
$methods = is_string($method) ? explode(',', $info['method']) : $method; $methods = is_string($method) ? explode(',', $info['method']) : $method;
foreach ($methods as $method) { foreach ($methods as $method) {
if (!in_array($method, ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD'])) { $method = strtolower($method);
if (!in_array($method, ['get', 'post', 'put', 'patch', 'delete', 'head'])) {
self::$warnings[] = $warningPreTitle . 'Not allowed method ' . $method . '... Disabling this route...'; self::$warnings[] = $warningPreTitle . 'Not allowed method ' . $method . '... Disabling this route...';
} }
} }

View File

@ -115,6 +115,18 @@ $dispatcher = FastRoute\cachedDispatcher(function (FastRoute\RouteCollector $r)
if ($route[0] === '*') { if ($route[0] === '*') {
$route[0] = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']; $route[0] = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD'];
} }
else {
if (is_string($route[0])) {
$route[0] = explode(',', $route[0]);
}
$toUpperCase = function(string $value): string {
return trim(strtoupper($value));
};
// convert to upper case, fast-route accepts only upper case
$route[0] = array_map($toUpperCase, $route[0]);
}
$aliases = [ $aliases = [
[':int', ':string', ':alphanum'], [':int', ':string', ':alphanum'],