/** * Get a route (if necessary) that responds when other available methods are present. * * @param \Http\Request $request * @param array $others * @return \Routing\Route * * @throws \Symfony\Component\Routing\Exception\MethodNotAllowedHttpException */ protected function getOtherMethodsRoute($request, array $others) { if ($request->method() == 'OPTIONS') { return new Route('OPTIONS', $request->path(), function () use($others) { return new Response('', 200, array('Allow' => implode(',', $others))); }); } $this->methodNotAllowed($others); }
/** * Find the patterned filters matching a request. * * @param \Http\Request $request * @return array */ public function findPatternFilters($request) { $results = array(); list($path, $method) = array($request->path(), $request->getMethod()); foreach ($this->patternFilters as $pattern => $filters) { if (str_is($pattern, $path)) { $merge = $this->patternsByMethod($method, $filters); $results = array_merge($results, $merge); } } foreach ($this->regexFilters as $pattern => $filters) { if (preg_match($pattern, $path)) { $merge = $this->patternsByMethod($method, $filters); $results = array_merge($results, $merge); } } return $results; }
/** * Validate a given rule against a route and request. * * @param \Routing\Route $route * @param \Http\Request $request * @return bool */ public function matches(Route $route, Request $request) { $regex = $route->getCompiled()->getRegex(); $path = $request->path() == '/' ? '/' : '/' . $request->path(); return preg_match($regex, rawurldecode($path)); }