diff --git a/src/FileRouter.php b/src/FileRouter.php index cdc498d..4fc90f0 100644 --- a/src/FileRouter.php +++ b/src/FileRouter.php @@ -129,16 +129,20 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface private function parseRequestPath(ServerRequestInterface $request): iterable { - $possibleAction = null; $path = urldecode($request->getUri()->getPath()); - if ($this->routePrefix !== '' && str_starts_with($path, $this->routePrefix)) { - $path = mb_substr($path, strlen($this->routePrefix)); + if ($this->routePrefix !== '') { + if (!str_starts_with($path, $this->routePrefix)) { + return; + } + $path = mb_substr($path, mb_strlen($this->routePrefix)); if ($path === '') { $path = '/'; } } + $possibleAction = null; + if ($path === '/') { yield [ $this->cleanClassname( diff --git a/tests/FileRouterTest.php b/tests/FileRouterTest.php index 88df990..28d6f74 100644 --- a/tests/FileRouterTest.php +++ b/tests/FileRouterTest.php @@ -377,6 +377,25 @@ public static function dataModularity(): iterable ]; } + public function testModularityFastPath(): void + { + $router = $this->createRouter(); + $router = $router + ->withNamespace('Yiisoft\\FileRouter\\Tests\\Support\\App5\\Module1') + ->withRoutePrefix('/module1'); + + + $handler = $this->createExceptionHandler(); + $request = new ServerRequest( + method: 'GET', + uri: '/module2', + ); + + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Not implemented from tests.'); + $router->process($request, $handler); + } + private function createRouter(): FileRouter { $container = new SimpleContainer([