/**
  * 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)
 {
     if (is_null($route->getCompiled()->getHostRegex())) {
         return true;
     }
     return preg_match($route->getCompiled()->getHostRegex(), $request->getHost());
 }
 /**
  * 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)
 {
     if ($route->httpOnly()) {
         return !$request->secure();
     } elseif ($route->secure()) {
         return $request->secure();
     }
     return true;
 }
 /**
  * Add the route to any look-up tables if necessary.
  *
  * @param  \Nova\Routing\Route  $route
  * @return void
  */
 protected function addLookups($route)
 {
     $action = $route->getAction();
     if (isset($action['as'])) {
         $this->nameList[$action['as']] = $route;
     }
     if (isset($action['controller'])) {
         $this->addToActionList($action, $route);
     }
 }
 /**
  * Add the route to any look-up tables if necessary.
  *
  * @param  \Nova\Routing\Route  $route
  * @return void
  */
 protected function addLookups($route)
 {
     // If the route has a name, we will add it to the name look-up table so that we
     // will quickly be able to find any route associate with a name and not have
     // to iterate through every route every time we need to perform a look-up.
     $action = $route->getAction();
     if (isset($action['as'])) {
         $this->nameList[$action['as']] = $route;
     }
     // When the route is routing to a controller we will also store the action that
     // is used by the route. This will let us reverse route to controllers while
     // processing a request and easily generate URLs to the given controllers.
     if (isset($action['controller'])) {
         $this->addToActionList($action, $route);
     }
 }
Exemple #5
0
 public function test()
 {
     $request = Request::instance();
     $uri = 'demo/test/{param1?}/{param2?}/{param3?}/{slug?}';
     //
     $route = new Route('GET', $uri, function () {
         echo 'Hello, World!';
     });
     $route->where('slug', '(.*)');
     // Match the Route.
     if ($route->matches($request)) {
         $route->bind($request);
         $content = '<pre>Route matched!</pre>';
     } else {
         $content = '<pre>Route not matched!</pre>';
     }
     $content .= '<pre>' . htmlspecialchars(var_export($route, true)) . '</pre>';
     return View::make('Default')->shares('title', __d('demos', 'Test'))->with('content', $content);
 }
Exemple #6
0
 /**
  * Parse the given filter and options.
  *
  * @param  \Closure|string  $filter
  * @param  array  $options
  * @return array
  */
 protected function parseFilter($filter, array $options)
 {
     $parameters = array();
     $original = $filter;
     if ($filter instanceof Closure) {
         $filter = $this->registerClosureFilter($filter);
     } else {
         if ($this->isInstanceFilter($filter)) {
             $filter = $this->registerInstanceFilter($filter);
         } else {
             list($filter, $parameters) = Route::parseFilter($filter);
         }
     }
     return compact('original', 'filter', 'parameters', 'options');
 }
 /**
  * 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));
 }
 /**
  * Get the scheme for the given route.
  *
  * @param  \Nova\Routing\Route  $route
  * @return string
  */
 protected function getRouteScheme($route)
 {
     if ($route->httpOnly()) {
         return $this->getScheme(false);
     } else {
         if ($route->httpsOnly()) {
             return $this->getScheme(true);
         }
     }
     return $this->getScheme(null);
 }
 /**
  * Get after filters
  *
  * @param  Route  $route
  * @return string
  */
 protected function getAfterFilters($route)
 {
     return implode(', ', array_keys($route->afterFilters()));
 }
 /**
  * Apply the applicable after filters to the route.
  *
  * @param  \Nova\Routing\Controller  $instance
  * @param  \Nova\Routing\Route  $route
  * @param  \Nova\Http\Request  $request
  * @param  string  $method
  * @return mixed
  */
 protected function assignAfter($instance, $route, $request, $method)
 {
     foreach ($instance->getAfterFilters() as $filter) {
         // If the filter applies, we will add it to the route, since it has already been
         // registered on the filterer by the controller, and will just let the normal
         // router take care of calling these filters so we do not duplicate logics.
         if ($this->filterApplies($filter, $request, $method)) {
             $route->after($this->getAssignableAfter($filter));
         }
     }
 }
 /**
  * Apply the applicable after filters to the route.
  *
  * @param  \Nova\Routing\Controller  $instance
  * @param  \Nova\Routing\Route  $route
  * @param  \Nova\Http\Request  $request
  * @param  string  $method
  * @return mixed
  */
 protected function assignAfter($instance, $route, $request, $method)
 {
     foreach ($instance->getAfterFilters() as $filter) {
         if ($this->filterApplies($filter, $request, $method)) {
             $route->after($this->getAssignableAfter($filter));
         }
     }
 }
Exemple #12
0
 /**
  * Call the given route's before filters.
  *
  * @param  \Nova\Routing\Route  $route
  * @param  \Nova\Http\Request  $request
  * @param  \Nova\Http\Response  $response
  * @return mixed
  */
 public function callRouteAfter($route, $request, $response)
 {
     foreach ($route->afterFilters() as $filter => $parameters) {
         $this->callRouteFilter($filter, $parameters, $route, $request, $response);
     }
 }
Exemple #13
0
 /**
  * Filter pattern filters that don't apply to the request verb.
  *
  * @param  string  $method
  * @param  array   $filters
  * @return array
  */
 protected function patternsByMethod($method, $filters)
 {
     $results = array();
     foreach ($filters as $filter) {
         // The idea here is to check and see if the pattern filter applies to this HTTP
         // request based on the request methods. Pattern filters might be limited by
         // the request verb to make it simply to assign to the given verb at once.
         if ($this->filterSupportsMethod($filter, $method)) {
             $parsed = Route::parseFilters($filter['name']);
             $results = array_merge($results, $parsed);
         }
     }
     return $results;
 }
Exemple #14
0
 /**
  * Parse the given filter string.
  *
  * @param  string  $filters
  * @return array
  */
 public static function parseFilters($filters)
 {
     return array_build(static::explodeFilters($filters), function ($key, $value) {
         return Route::parseFilter($value);
     });
 }
 /**
  * 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());
 }