RouteMap: Remove check for captures (push this into regex route's dispatch)

This commit is contained in:
PJ Dietz 2015-05-07 22:49:39 -04:00
parent 1a49a4ac6c
commit 7a53a02c5f
2 changed files with 5 additions and 7 deletions

View File

@ -81,12 +81,7 @@ class RouteMap implements RouteMapInterface
// Try each of the routes. // Try each of the routes.
foreach ($this->patternRoutes as $route) { foreach ($this->patternRoutes as $route) {
if ($route->matchesRequestTarget($requestTarget, $captures)) { if ($route->matchesRequestTarget($requestTarget)) {
if (is_array($captures)) {
foreach ($captures as $key => $value) {
$request = $request->withAttribute($key, $value);
}
}
$route->dispatch($request, $response); $route->dispatch($request, $response);
return; return;
} }

View File

@ -3,6 +3,9 @@
namespace WellRESTed\Test\Unit\Routing; namespace WellRESTed\Test\Unit\Routing;
use Prophecy\Argument; use Prophecy\Argument;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use WellRESTed\Routing\MethodMapInterface;
use WellRESTed\Routing\Route\RouteInterface; use WellRESTed\Routing\Route\RouteInterface;
use WellRESTed\Routing\RouteMap; use WellRESTed\Routing\RouteMap;
@ -31,7 +34,6 @@ class RouteMapTest extends \PHPUnit_Framework_TestCase
$this->route->getMethodMap()->willReturn($this->methodMap->reveal()); $this->route->getMethodMap()->willReturn($this->methodMap->reveal());
$this->route->getType()->willReturn(RouteInterface::TYPE_STATIC); $this->route->getType()->willReturn(RouteInterface::TYPE_STATIC);
$this->route->getTarget()->willReturn("/"); $this->route->getTarget()->willReturn("/");
$this->route->matchesRequestTarget(Argument::cetera())->willReturn(true);
$this->factory = $this->prophesize('WellRESTed\Routing\Route\RouteFactory'); $this->factory = $this->prophesize('WellRESTed\Routing\Route\RouteFactory');
$this->factory->create(Argument::any())->willReturn($this->route->reveal()); $this->factory->create(Argument::any())->willReturn($this->route->reveal());
@ -186,6 +188,7 @@ class RouteMapTest extends \PHPUnit_Framework_TestCase
$this->request->getRequestTarget()->willReturn($target); $this->request->getRequestTarget()->willReturn($target);
$this->route->getTarget()->willReturn($target); $this->route->getTarget()->willReturn($target);
$this->route->getType()->willReturn(RouteInterface::TYPE_PATTERN); $this->route->getType()->willReturn(RouteInterface::TYPE_PATTERN);
$this->route->matchesRequestTarget(Argument::cetera())->willReturn(true);
$this->routeMap->add("GET", $target, "middleware"); $this->routeMap->add("GET", $target, "middleware");