Beispiel #1
0
 /**
  * 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);
     }
 }
Beispiel #2
0
 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());
 }