Skip to content

Commit

Permalink
add baseUrl handling in route listener
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefano Torresi committed Oct 26, 2013
1 parent 107a69d commit 499b941
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion library/Phlyty/App.php
Expand Up @@ -742,12 +742,16 @@ protected function registerRouteListener()

$request = $e->getParam('request');
$routes = $this->routesByMethod[$method];

$baseUrl = $request->getBaseUrl();
$baseUrlLength = strlen($baseUrl) ?: null;

foreach ($routes as $index => $route) {
if ($index <= $this->routeIndex) {
// Skip over routes we've already looked at
continue;
}
$result = $route->route()->match($request);
$result = $route->route()->match($request, $baseUrlLength);
if ($result) {
$this->routeIndex = $index;
$this->params = $result;
Expand Down
16 changes: 16 additions & 0 deletions tests/PhlytyTest/AppTest.php
Expand Up @@ -523,4 +523,20 @@ public function testCanProvideViewModelPrototype()
$this->assertNotInstanceOf('Phlyty\View\MustacheViewModel', $test);
$this->assertNotSame($model, $test);
}

public function testRouteMatchWithBaseUrl()
{
$foo = $this->app->get('/foo', function ($app) {
$app->response()->setContent('Foo bar!');
});

$this->app->request()->setBaseUrl('/bar/baz');

$request = $this->app->request();
$request->setMethod('GET')
->setUri('/bar/baz/foo');
$this->app->run();
$response = $this->app->response();
$this->assertEquals('Foo bar!', $response->sentContent);
}
}

0 comments on commit 499b941

Please sign in to comment.