/** * Match if current Route match to the request url, method and type * * @param Route $route * @return bool */ private function match(Route $route) { if (!in_array($this->routeRequest->getRequestMethod(), $route->getMethods())) { return false; } if (!$this->routeRequest->isAjax() && 'ajax' == $route->getType()) { return false; } if (!preg_match($route->getPattern(), $this->routeRequest->getRequestUrl())) { return false; } return true; }
/** * @test */ public function shouldCreateRouteWithNamedParamMatchToRegex() { $route = new Route('GET|POST /some_page/@id', ['id' => '[a-z]{2}\\-[a-z]{4}'], 'A->index'); $this->assertEquals('|^/some_page/([a-z]{2}\\-[a-z]{4})$|', $route->getPattern()); }