Router uses only the request's path for routing
This commit is contained in:
parent
3b18d1dcdb
commit
1be4ff7691
|
|
@ -77,7 +77,8 @@ class Router implements RouterInterface
|
||||||
|
|
||||||
public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next)
|
public function dispatch(ServerRequestInterface $request, ResponseInterface $response, $next)
|
||||||
{
|
{
|
||||||
$requestTarget = $request->getRequestTarget();
|
// Use only the path for routing.
|
||||||
|
$requestTarget = parse_url($request->getRequestTarget(), PHP_URL_PATH);
|
||||||
|
|
||||||
$route = $this->getStaticRoute($requestTarget);
|
$route = $this->getStaticRoute($requestTarget);
|
||||||
if ($route) {
|
if ($route) {
|
||||||
|
|
|
||||||
|
|
@ -363,6 +363,25 @@ class RouterTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->request->withAttribute("pathVariables", $variables)->shouldHaveBeenCalled();
|
$this->request->withAttribute("pathVariables", $variables)->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::dispatch
|
||||||
|
* @covers ::registerRouteForTarget
|
||||||
|
*/
|
||||||
|
public function testMatchesPathAgainstRouteWithoutQuery()
|
||||||
|
{
|
||||||
|
$target = "/my/path?cat=molly&dog=bear";
|
||||||
|
|
||||||
|
$this->request->getRequestTarget()->willReturn($target);
|
||||||
|
$this->route->getTarget()->willReturn($target);
|
||||||
|
$this->route->getType()->willReturn(RouteInterface::TYPE_PATTERN);
|
||||||
|
$this->route->matchesRequestTarget(Argument::cetera())->willReturn(true);
|
||||||
|
|
||||||
|
$this->router->register("GET", $target, "middleware");
|
||||||
|
$this->router->dispatch($this->request->reveal(), $this->response->reveal(), $this->next);
|
||||||
|
|
||||||
|
$this->route->matchesRequestTarget("/my/path")->shouldHaveBeenCalled();
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// No Matching Routes
|
// No Matching Routes
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue