Exemple #1
0
 /**
  * Returns the regex needed to match the route.
  *
  * @access  public
  * @return  string
  */
 public function compileRegex()
 {
     $route = $this->route->getUri();
     if (strpos($route, '?')) {
         $route = preg_replace('@\\/{([\\w]+)\\?}@', '(?:/{$1})?', $route);
     }
     $route = preg_replace('/{([a-z0-9_-]+)}/i', '(?P<$1>[^/]+)', $route);
     if (substr($route, -1) === '/') {
         $route .= '?';
     }
     return "%^{$route}\$%s";
 }
Exemple #2
0
 public function testClosureRoute()
 {
     $route = new Route('/', 'index', function () {
         return 'Hello';
     });
     $this->assertEquals('/', $route->getUri());
     $this->assertInstanceOf('Closure', $route->getAction());
     $this->assertEquals('Hello', call_user_func($route->getAction()));
 }