Example #1
0
 private function bind($path, $call, array $options = [])
 {
     $options = $this->processOptions($options);
     if (!isset($options['method']) or !in_array($this->method, $options['method'])) {
         return;
     }
     $path = $this->helper->normalize($path);
     $path = implode($this->groups) . $path;
     $route = new Route();
     $route->setOrigin($path);
     $path = $this->helper->compile($path);
     $prefix = null;
     if ($this->domain) {
         $route->setDomain($this->domain);
         $prefix = '<' . $this->domain . '>/';
     }
     $key = null;
     if ($path) {
         $key = $prefix . $path;
     }
     $route->setPath($path);
     $route->setCallback($call);
     $route->setOptions($options);
     if ($this->controller) {
         $route->setController($this->controller);
     }
     if ($this->rest) {
         $route->setRest($this->rest);
     }
     if (isset($this->routes[$key])) {
         throw new RouteException(sprintf('Path %s already exists', $key));
     }
     $this->routes[$key] = $this->lastRoute = $route;
 }
Example #2
0
 public function checkWhere(Route $route)
 {
     $where = $route->getWhere();
     $params = $route->getParams();
     foreach ($params as $key => $value) {
         if (isset($where[$key])) {
             if (!preg_match($where[$key]['regexp'], $value)) {
                 if (isset($where[$key]['default'])) {
                     $params[$key] = $where[$key]['default'];
                     $route->setParams($params);
                 } else {
                     return false;
                 }
             }
         }
     }
     return true;
 }