示例#1
0
 /**
  * @param   \Phphilosophy\Router\Route  $route  A route instance
  *
  * @return  string  The pattern as a regex
  */
 private function parse(Route $route)
 {
     // The parameter token namespace
     $tokens = array_keys($this->tokens);
     // The route pattern
     $pattern = $route->getPattern();
     // Search for all kinds of parameters and translate them
     foreach ($tokens as $token) {
         $pattern = $this->translate($token, $pattern);
     }
     // The parsed regular expression ready for matching
     return '#^' . $pattern . '$#D';
 }
示例#2
0
 /**
  * @access  private
  * @param   \Phphilosophy\Router\Route  $route  A route instance
  * @param   string                      $uri    The request URI
  * @param   string                      $method The request method
  * @return  mixed
  */
 private function match($route, $uri, $method)
 {
     // The pattern given by the user
     $pattern = $route->getPattern();
     // The regular expression
     $regex = $this->patternToRegex($pattern);
     // The methods of this route
     $methods = $route->getMethods();
     // Run the callable
     if (preg_match($regex, $uri) && in_array($method, $methods)) {
         $params = $this->getParams($uri, $pattern);
         $this->match = true;
         call_user_func_array($route->getAction(), $params);
     }
 }
示例#3
0
 /**
  * @param   \Phphilosophy\Router\Route  $route  A route instance
  *
  * @return  void
  */
 private function match(Route $route)
 {
     // The pattern given by the user
     $pattern = $route->getPattern();
     // Run the callable
     if ($this->matcher->match($route) && $this->guard($route)) {
         $params = $this->parser->parse($pattern);
         $this->match = true;
         call_user_func_array($route->getAction(), $params);
     }
 }