Ejemplo n.º 1
0
    function testPlaceHolder()
    {
        $route = PatternCompiler::compile('/blog/:year/:month');
        $pattern = '#^    /blog
    /(?P<year>[^/]+)
    /(?P<month>[^/]+)
$#xs';
        is($pattern, $route['compiled']);
    }
Ejemplo n.º 2
0
Archivo: Mux.php Proyecto: number0/Pux
 public function add($pattern, $callback, $options = array())
 {
     if (is_string($callback) && strpos($callback, ':') !== false) {
         $callback = explode(':', $callback);
     }
     // compile place holder to patterns
     $pcre = strpos($pattern, ':') !== false;
     if ($pcre) {
         $routeArgs = PatternCompiler::compile($pattern, $options);
         // generate a pcre pattern route
         $route = array(true, $routeArgs['compiled'], $callback, $routeArgs);
         if (isset($options['id'])) {
             $this->routesById[$options['id']] = $route;
         }
         return $this->routes[] = $route;
     } else {
         $route = array(false, $pattern, $callback, $options);
         if (isset($options['id'])) {
             $this->routesById[$options['id']] = $route;
         }
         // generate a simple string route.
         return $this->routes[] = $route;
     }
 }
Ejemplo n.º 3
0
Archivo: Mux.php Proyecto: kpb90/Pux
 public function add($pattern, $callback, array $options = array())
 {
     if (is_string($callback) && strpos($callback, ':') !== false) {
         $callback = explode(':', $callback);
     }
     // Convert request method constraint to constant if it's passed by string
     if (isset($options['method']) && is_string($options['method'])) {
         $options['method'] = self::getRequestMethodConstant($options['method']);
     }
     // compile place holder to patterns
     $pcre = strpos($pattern, ':') !== false;
     if ($pcre) {
         $routeArgs = is_integer($callback) ? PatternCompiler::compilePrefix($pattern, $options) : PatternCompiler::compile($pattern, $options);
         // generate a pcre pattern route
         $route = array(true, $routeArgs['compiled'], $callback, $routeArgs);
         if (isset($options['id'])) {
             $this->routesById[$options['id']] = $route;
         }
         return $this->routes[] = $route;
     } else {
         $route = array(false, $pattern, $callback, $options);
         if (isset($options['id'])) {
             $this->routesById[$options['id']] = $route;
         }
         // generate a simple string route.
         return $this->routes[] = $route;
     }
 }