Skip to content

Commit

Permalink
Merge pull request #12 from yiisoft/optimization
Browse files Browse the repository at this point in the history
Add optimisation
  • Loading branch information
xepozz authored Jan 11, 2024
2 parents 1fa398a + 74f3376 commit 39f6c34
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/FileRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
19 changes: 19 additions & 0 deletions tests/FileRouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down

0 comments on commit 39f6c34

Please sign in to comment.