public function testRouteMatch() { $router = new Router(); $router->addRouteSequence('Itkg\\Tests\\Core\\Mock\\RouteMatcher'); $matcher = new RequestMatcher($router); $request = Request::createFromGlobals(); $this->assertTrue($matcher->matches($request)); $this->assertEquals('Itkg\\Tests\\Core\\Mock\\My', $request->attributes->get('controller')); $this->assertEquals('index', $request->attributes->get('action')); $params = $request->attributes->get('route_params'); $this->assertArrayHasKey('posts', $params['params']); }
/** * @param Request $request * @return bool * @throws \RuntimeException */ public function matches(Request $request) { $pathInfo = trim($request->getPathInfo(), '/'); foreach ($this->router->getRouteSequences() as $sequence) { if (!class_exists($sequence)) { throw new \RuntimeException(sprintf('Route sequence %s does not exist', $sequence)); } $routeMatcher = new $sequence($pathInfo, $this->router->getRoutes()); $params = $routeMatcher->process(); if (is_array($params)) { return $this->processParams($request, $params); } } return false; }