Example #1
0
 /**
  *  Dispatch incoming request trough routing tree
  */
 private static final function routeUser()
 {
     // Check if request is at least suitable to resolve
     if (self::$routingDictionaryCounter != 0) {
         /** @var RouterPathObject | null $routeRoot */
         $routeRoot = null;
         $aliasCounter = 0;
         foreach (self::$routerPath as $path => $v) {
             // If current route path is in dictionary of exact routes
             if (isset(self::$routingDictionary[$path])) {
                 $routeNum = self::$routingDictionary[$path];
                 // Start routing from root
                 if (!isset($routeRoot)) {
                     $routeRoot = self::$routingPathObjects[$routeNum];
                 } else {
                     if ($newRoot = $routeRoot->getExtensionForRouteId($routeNum)) {
                         $routeRoot = $newRoot;
                         $aliasCounter = 0;
                     } else {
                         if (isset($routeRoot->virtualExtStr)) {
                             if ($name = $routeRoot->getAliasNameForCellNumber($aliasCounter)) {
                                 self::$requestObject->__setPathParameter($name, $path);
                                 $aliasCounter++;
                             }
                             $routeRoot = $routeRoot->virtualExtStr;
                             $aliasCounter = 0;
                         }
                     }
                 }
             } else {
                 if (!isset($routeRoot)) {
                     continue;
                 }
                 // Put Variable into Request Path Parameter with attached variable
                 if ($name = $routeRoot->getAliasNameForCellNumber($aliasCounter)) {
                     self::$requestObject->__setPathParameter($name, $path);
                     $aliasCounter++;
                 }
                 // If exists virtual route for this branch - use it
                 if (isset($routeRoot->virtualExtStr)) {
                     $routeRoot = $routeRoot->virtualExtStr;
                     $aliasCounter = 0;
                 }
             }
         }
         // Proceed to route
         if (isset($routeRoot)) {
             self::doRoute($routeRoot);
             return;
         }
     }
     // Produce not found in all failed cases
     self::doRouteError(404);
 }