/** * Determine if the filter fails the "on" constraint. * * @param array $filter * @param \Nova\Http\Request $request * @param string $method * @return bool */ protected function filterFailsOn($filter, $request, $method) { $on = array_get($filter, 'options.on'); if (is_null($on)) { return false; } // If the "on" is a string, we will explode it on the pipe so you can set any // amount of methods on the filter constraints and it will still work like // you specified an array. Then we will check if the method is in array. if (is_string($on)) { $on = explode('|', $on); } return !in_array(strtolower($request->getMethod()), $on); }
/** * Determine if any routes match on another HTTP verb. * * @param \Nova\Http\Request $request * @return array */ protected function checkForAlternateVerbs($request) { $methods = array_diff(Router::$verbs, array($request->getMethod())); // Here we will spin through all verbs except for the current request verb and // check to see if any routes respond to them. If they do, we will return a // proper error response with the correct headers on the response string. $others = array(); foreach ($methods as $method) { if (!is_null($this->check($this->get($method), $request, false))) { $others[] = $method; } } return $others; }
/** * Determine if any routes match on another HTTP verb. * * @param \Nova\Http\Request $request * @return array */ protected function checkForAlternateMethods($request) { $methods = array_diff(Router::$methods, array($request->getMethod())); // $others = array(); foreach ($methods as $method) { if (!is_null($this->check($this->get($method), $request, false))) { $others[] = $method; } } return $others; }
/** * Determine if the filter fails the "on" constraint. * * @param array $filter * @param \Nova\Http\Request $request * @param string $method * @return bool */ protected function filterFailsOn($filter, $request, $method) { $on = array_get($filter, 'options.on'); if (is_null($on)) { return false; } if (is_string($on)) { $on = explode('|', $on); } return !in_array(strtolower($request->getMethod()), $on); }
/** * 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; }
/** * 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; }
/** * 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) { return in_array($request->getMethod(), $route->methods()); }