/** * Determines if a given Route URI matches the request URI. * If match, sets Router property $route and assembles the matched query * vars and adds them to Request property $path_params. However, if * the HTTP method is not allowed, a 405 Status error is returned. * * @param Route $route The \Phpf\Route\Route object. * @param string $uri Request URI. * @param string $http_method Request HTTP method. * @return boolean True if match and set up, otherwise false. */ protected function matchRoute(Route $route, $uri, $http_method) { $qvs = array(); $route_uri = $this->parseRoute($route->uri, $qvs); if (preg_match('#^/?' . $route_uri . '/?$#i', $uri, $route_vars)) { // check if HTTP method is allowed if (!$route->isMethodAllowed($http_method)) { // send 405 with the 'Allow' header $exception = new \Phpf\Route\Exception\HttpMethodNotAllowed(); $exception->setRequestedMethod($http_method); $exception->setAllowedMethods($route->getMethods()); $this->response->addHeader('Allow', $exception->getAllowedMethodsString()); $this->error(405, $exception, $route); } $this->route = $route; unset($route_vars[0]); if (!empty($qvs) && !empty($route_vars)) { $this->request->setPathParams(array_combine($qvs, $route_vars)); } return true; } return false; }