Example #1
0
 public function tryRoute($route)
 {
     $pathParts = $this->request->getPathParts();
     //-------
     // Set up default values for everything:
     //-------
     list($thisNamespace, $thisController, $thisAction) = $this->getDefaults($route);
     $routeParts = array_filter(explode('/', $route['route']));
     $routeMatches = true;
     while (count($routeParts)) {
         $routePart = array_shift($routeParts);
         $pathPart = array_shift($pathParts);
         switch ($routePart) {
             case ':namespace':
                 if (!is_null($pathPart)) {
                     $thisNamespace = $pathPart;
                 }
                 break;
             case ':controller':
                 if (!is_null($pathPart)) {
                     $thisController = $pathPart;
                 }
                 break;
             case ':action':
                 if (!is_null($pathPart)) {
                     $thisAction = $pathPart;
                 }
                 break;
             default:
                 if (substr($routePart, 0, 1) == '(' && substr($routePart, -1) == ')') {
                     if (preg_match('/^' . $routePart . '$/', $pathPart)) {
                         break;
                     }
                 }
                 if ($routePart != $pathPart) {
                     $routeMatches = false;
                 }
         }
         if (!$routeMatches || !count($pathParts)) {
             break;
         }
     }
     $thisArgs = $pathParts;
     if ($routeMatches) {
         $route = array('namespace' => $thisNamespace, 'controller' => $thisController, 'action' => $thisAction, 'args' => $thisArgs, 'callback' => $route['callback']);
         if ($this->application->isValidRoute($route)) {
             return $route;
         }
     }
     return null;
 }