Beispiel #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;
 }
Beispiel #2
0
 public function checkController(Route $route, $uri)
 {
     if (!$route->getController()) {
         return true;
     }
     $path = $route->getPath();
     $slice = substr($uri, strlen($path));
     if (!$slice) {
         return false;
     }
     $filtered = array_filter(explode('/', $slice));
     $action = reset($filtered);
     $action = preg_replace('~\\W~', '', (string) $action);
     if (!$action) {
         return false;
     }
     $controller = $route->getCallback();
     try {
         $class = new ReflectionClass($controller);
     } catch (ReflectionException $e) {
         return false;
     }
     if (!$class->hasMethod($action)) {
         return false;
     }
     if (!$class->getMethod($action)->isPublic()) {
         return false;
     }
     $route->setCallback($controller . '::' . $class->getMethod($action)->getName());
     return true;
 }