function testPlaceHolder() { $route = PatternCompiler::compile('/blog/:year/:month'); $pattern = '#^ /blog /(?P<year>[^/]+) /(?P<month>[^/]+) $#xs'; is($pattern, $route['compiled']); }
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; } }
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; } }