Example #1
0
 public function match($method, $route)
 {
     $method = strtolower($method);
     if (!is_array($route)) {
         $route = trim($route, "/");
         $route = explode("/", $route);
         //Root is defined as / instead of empty space
         if (count($route) === 1 && $route[0] == "") {
             $route[0] = "/";
         }
     } else {
         if (empty($route)) {
             $route = ["/"];
         }
     }
     $node = $this->nodes;
     $params = [];
     foreach ($route as $fragment) {
         //Search for fragment as pre-defined piece of the URI
         $child = $node->getChild(strtolower($fragment));
         if ($child === false) {
             //Search for fragment as a parameter of the URI
             $child = $node->getChild(":");
             if ($child === false) {
                 return false;
             }
             $params[] = $fragment;
         }
         $node = $child;
     }
     $routes = $node->getRoutes();
     if (isset($routes[$method])) {
         $route = new Route();
         $route->setProcedure($routes[$method]["target"]);
         $route->setParams($params);
         $route->setProperties($routes[$method]["properties"]);
         return $route;
     } else {
         if (count($routes) > 0) {
             return true;
         } else {
             return false;
         }
     }
 }