/** * Dispatches the matched route, or handles a failed one. * * @param ServerRequestInterface $request The request object to match * against and pass to the callback. */ public function dispatch(ServerRequestInterface $request) { if ($route = $this->matcher->match($request)) { foreach ($route->getAttributes() as $key => $value) { $request = $request->withAttribute($key, $value); } echo call_user_func($route->getCallback(), $request); } }
public function testRouteAttributesArePopulatedWithValues() { $route = new Route('test.route', '/api/:version/users/:id', function () { }); $matcher = new Matcher(new Collection([$route])); $request = $this->getRequestWithPath('/api/v3/users/65535'); $matcher->match($request); $this->assertEquals(['version' => 'v3', 'id' => '65535'], $route->getAttributes()); }