From 497b499c7714199ef54e03e802a84386818a82a8 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 21 Jun 2024 13:01:01 +0900 Subject: [PATCH] refactor: rename method name --- system/Router/AutoRouterImproved.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/system/Router/AutoRouterImproved.php b/system/Router/AutoRouterImproved.php index 57d5ca0ad610..09a796ae0f3c 100644 --- a/system/Router/AutoRouterImproved.php +++ b/system/Router/AutoRouterImproved.php @@ -162,7 +162,7 @@ private function searchFirstController(): bool $segment = array_shift($segments); $controllerPos++; - $class = $this->translateURIDashes($segment); + $class = $this->translateURI($segment); // as soon as we encounter any segment that is not PSR-4 compliant, stop searching if (! $this->isValidSegment($class)) { @@ -209,7 +209,7 @@ private function searchLastDefaultController(): bool } $namespaces = array_map( - fn ($segment) => $this->translateURIDashes($segment), + fn ($segment) => $this->translateURI($segment), $segments ); @@ -307,7 +307,7 @@ public function getRoute(string $uri, string $httpVerb): array $method = ''; if ($methodParam !== null) { - $method = $httpVerb . $this->translateURIDashes($methodParam); + $method = $httpVerb . $this->translateURI($methodParam); $this->checkUriForMethod($method); } @@ -544,7 +544,10 @@ private function isValidSegment(string $segment): bool return (bool) preg_match('/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/', $segment); } - private function translateURIDashes(string $segment): string + /** + * Translates URI segment to CamelCase or replaces `-` with `_`. + */ + private function translateURI(string $segment): string { if ($this->translateUriToCamelCase) { if (strtolower($segment) !== $segment) {