예제 #1
0
    function testPlaceHolder()
    {
        $route = PatternCompiler::compile('/blog/:year/:month');
        $pattern = '#^    /blog
    /(?P<year>[^/]+)
    /(?P<month>[^/]+)
$#xs';
        is($pattern, $route['compiled']);
    }
예제 #2
0
파일: Mux.php 프로젝트: 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;
     }
 }
예제 #3
0
파일: Mux.php 프로젝트: 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;
     }
 }