Exemplo n.º 1
0
 /**
  * Validate a given rule against a route and request.
  *
  * @param  \Nova\Routing\Route  $route
  * @param  \Nova\Http\Request  $request
  * @return bool
  */
 public function matches(Route $route, Request $request)
 {
     $path = $request->path() == '/' ? '/' : '/' . $request->path();
     return preg_match($route->getCompiled()->getRegex(), rawurldecode($path));
 }
Exemplo n.º 2
0
 /**
  * Find the patterned filters matching a request.
  *
  * @param  \Nova\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) {
         // To find the patterned middlewares for a request, we just need to check these
         // registered patterns against the path info for the current request to this
         // applications, and when it matches we will merge into these middlewares.
         if (str_is($pattern, $path)) {
             $merge = $this->patternsByMethod($method, $filters);
             $results = array_merge($results, $merge);
         }
     }
     foreach ($this->regexFilters as $pattern => $filters) {
         // To find the patterned middlewares for a request, we just need to check these
         // registered patterns against the path info for the current request to this
         // applications, and when it matches we will merge into these middlewares.
         if (preg_match($pattern, $path)) {
             $merge = $this->patternsByMethod($method, $filters);
             $results = array_merge($results, $merge);
         }
     }
     return $results;
 }
Exemplo n.º 3
0
 /**
  * Get a route (if necessary) that responds when other available methods are present.
  *
  * @param  \Nova\Http\Request  $request
  * @param  array  $others
  * @return \Nova\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);
 }
Exemplo n.º 4
0
 /**
  * Find the patterned filters matching a request.
  *
  * @param  \Nova\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;
 }