Пример #1
0
 /**
  * main method!
  *
  * @param string $path
  * @return boolean
  */
 public static function run($path = "")
 {
     $splitFlag = preg_quote(self::$splitFlag, "/");
     $path_array = array();
     if (!empty($path)) {
         $isPart = true;
         if ($path[0] == "/") {
             $path = substr($path, 1);
         }
         $path_array = preg_split("/[{$splitFlag}\\/]/", $path, -1);
     } else {
         $isPart = false;
         if (!empty(self::$pathInfo)) {
             $url = self::$pathInfo;
         } else {
             if (!empty($_GET["PATH_INFO"])) {
                 $url = $_GET["PATH_INFO"];
             } elseif (!empty($_SERVER['PATH_INFO'])) {
                 $url = $_SERVER["PATH_INFO"];
             } elseif (!empty($_SERVER['REQUEST_URI'])) {
                 $url = $_SERVER["REQUEST_URI"];
             }
             $url = preg_replace("/(\\/+)/", "/", $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . "/" . $url);
             $url_parsed = parse_url($url, PHP_URL_PATH);
             if (!empty($url_parsed)) {
                 $url = $url_parsed;
             }
         }
         if (!empty($url)) {
             if ($url[0] == "/") {
                 $url = substr($url, 1);
             }
             $path_array = preg_split("/[{$splitFlag}\\/]/", $url, -1);
         }
     }
     $zone = !empty($path_array[0]) ? $path_array[0] : self::$defaultZone;
     $page = !empty($path_array[1]) ? $path_array[1] : self::$defaultPage;
     $entry = !empty($path_array[2]) ? $path_array[2] : self::$defaultEntry;
     if (self::$zoneAlias && ($key = array_search($zone, self::$zoneAlias)) !== false) {
         $zone = $key;
     }
     if (!$isPart) {
         self::$zone = $zone;
         self::$page = $page;
         self::$entry = $entry;
     } else {
         if ($zone == self::$zone && $page == self::$page && $entry == self::$entry) {
             self::debug("part ignored [{$path}]");
             return false;
         }
     }
     $app_file = self::$appDir . DIRECTORY_SEPARATOR . $zone . DIRECTORY_SEPARATOR . $page . ".page.php";
     if (!is_file($app_file)) {
         self::debug("file[{$app_file}] does not exists");
         return false;
     } else {
         require_once realpath($app_file);
     }
     $method = "Page" . $entry;
     $classname = $zone . "_" . $page;
     if (!class_exists($classname, false)) {
         self::debug("class[{$classname}] does not exists");
         return false;
     }
     $path_array[0] = $zone;
     $path_array[1] = $page;
     $path_array[2] = $entry;
     $classInstance = new $classname($path_array);
     if (!method_exists($classInstance, $method)) {
         self::debug("method[{$method}] does not exists in class[{$classname}]");
         return false;
     }
     return call_user_func(array(&$classInstance, $method), $path_array);
 }
Пример #2
0
 /**
  * main method!
  *
  * @param string $path
  * @return boolean
  */
 public static function run($path = "")
 {
     $splitFlag = preg_quote(self::$splitFlag, "/");
     $path_array = array();
     if (!empty($path)) {
         $isPart = true;
     } else {
         $isPart = false;
         if (!empty($_SERVER['PATH_INFO'])) {
             $path = $_SERVER["PATH_INFO"];
         } elseif (!empty($_SERVER['REQUEST_URI'])) {
             $path = $_SERVER["REQUEST_URI"];
         } else {
             self::debug("path not set in params or server.path_info, server.request_uri");
             return false;
         }
     }
     /* Skip leading / */
     $len = strlen($path);
     $start = 0;
     for ($start = 0; $start < $len; $start++) {
         if ($path[$start] != '/') {
             break;
         }
     }
     $url_parsed = parse_url(substr($path, $start), PHP_URL_PATH);
     if (!empty($url_parsed)) {
         $url = $url_parsed;
     } else {
         $url = $path;
     }
     self::$pathInfo = $url;
     $path_array = preg_split("/[{$splitFlag}\\/]/", $url, -1);
     $zone = !empty($path_array[0]) ? $path_array[0] : self::$defaultZone;
     $page = !empty($path_array[1]) ? $path_array[1] : self::$defaultPage;
     $entry = !empty($path_array[2]) ? $path_array[2] : self::$defaultEntry;
     if (self::$zoneAlias && ($key = array_search($zone, self::$zoneAlias)) !== false) {
         $zone = $key;
     }
     if (!$isPart) {
         self::$zone = $zone;
         self::$page = $page;
         self::$entry = $entry;
     } else {
         if ($zone == self::$zone && $page == self::$page && $entry == self::$entry) {
             self::debug("part ignored [{$path}]");
             return false;
         }
     }
     $app_file = self::$appDir . DIRECTORY_SEPARATOR . $zone . DIRECTORY_SEPARATOR . $page . ".page.php";
     if (!is_file($app_file)) {
         self::debug("file[{$app_file}] does not exists");
         return false;
     } else {
         require_once realpath($app_file);
     }
     $method = "Page" . $entry;
     $classname = $zone . "_" . $page;
     if (!class_exists($classname, false)) {
         self::debug("class[{$classname}] does not exists");
         return false;
     }
     $path_array[0] = $zone;
     $path_array[1] = $page;
     $path_array[2] = $entry;
     $classInstance = new $classname($path_array);
     if (!method_exists($classInstance, $method)) {
         self::debug("method[{$method}] does not exists in class[{$classname}]");
         return false;
     }
     return call_user_func(array(&$classInstance, $method), $path_array);
 }