From 0d96fbaaa8355d5f385de31b83d1c8d8694186be Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 21 Jun 2024 12:46:32 +0900 Subject: [PATCH] fix: Auto Routing (Improved) Default Method Fallback does not work with $translateUriToCamelCase --- system/Router/AutoRouterImproved.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/system/Router/AutoRouterImproved.php b/system/Router/AutoRouterImproved.php index 0db5ebc1ddc2..0b1ba6b642d5 100644 --- a/system/Router/AutoRouterImproved.php +++ b/system/Router/AutoRouterImproved.php @@ -519,10 +519,17 @@ private function checkUriForMethod(string $method): void return; } - if (! in_array($method, get_class_methods($this->controller), true)) { - throw new PageNotFoundException( - '"' . $this->controller . '::' . $method . '()" is not found.' - ); + // If `getSomeMethod()` exists, only `controller/some-method` should be + // accessible. But if a visitor navigates to `controller/somemethod`, + // `getSomemethod()` will be checked, and method_exists() will return true. + if (method_exists($this->controller, $method)) { + // We do not permit `controller/somemethod`, so check the exact method + // name. + if (! in_array($method, get_class_methods($this->controller), true)) { + throw new PageNotFoundException( + '"' . $this->controller . '::' . $method . '()" is not found.' + ); + } } }