當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Bootstrap::path_info方法代碼示例

本文整理匯總了PHP中Bootstrap::path_info方法的典型用法代碼示例。如果您正苦於以下問題:PHP Bootstrap::path_info方法的具體用法?PHP Bootstrap::path_info怎麽用?PHP Bootstrap::path_info使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Bootstrap的用法示例。


在下文中一共展示了Bootstrap::path_info方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setup_by_url

 /**
  * 根據URL初始化
  */
 private static function setup_by_url(&$request_mode)
 {
     # 處理base_url
     if (null === self::$base_url && isset($_SERVER["SCRIPT_NAME"]) && $_SERVER["SCRIPT_NAME"]) {
         $base_url_len = strrpos($_SERVER["SCRIPT_NAME"], '/');
         if ($base_url_len) {
             $base_url = substr($_SERVER["SCRIPT_NAME"], 0, $base_url_len);
             if (preg_match('#^(.*)/wwwroot$#', $base_url, $m)) {
                 # 特殊處理wwwroot目錄
                 $base_url = $m[1];
                 $base_url_len = strlen($base_url);
             }
             if (strtolower(substr($_SERVER['REQUEST_URI'], 0, $base_url_len)) == strtolower($base_url)) {
                 self::$base_url = $base_url;
             }
         }
     }
     if (isset($_SERVER['PATH_INFO'])) {
         $pathinfo = $_SERVER["PATH_INFO"];
     } else {
         if (isset($_SERVER["PATH_TRANSLATED"])) {
             list($null, $pathinfo) = explode('index' . EXT, $_SERVER["PATH_TRANSLATED"], 2);
         } elseif (isset($_SERVER['REQUEST_URI'])) {
             $request_uri = $_SERVER['REQUEST_URI'];
             if (self::$base_url) {
                 $request_uri = substr($request_uri, strlen(self::$base_url));
             }
             // 移除查詢參數
             list($pathinfo) = explode('?', $request_uri, 2);
         } elseif (isset($_SERVER['PHP_SELF'])) {
             $pathinfo = $_SERVER['PHP_SELF'];
         } elseif (isset($_SERVER['REDIRECT_URL'])) {
             $pathinfo = $_SERVER['REDIRECT_URL'];
         } else {
             $pathinfo = false;
         }
     }
     # 過濾pathinfo傳入進來的服務器默認頁
     if (false !== $pathinfo && ($indexpagelen = strlen(self::$config['core']['server_index_page'])) && substr($pathinfo, -1 - $indexpagelen) == '/' . self::$config['core']['server_index_page']) {
         $pathinfo = substr($pathinfo, 0, -$indexpagelen);
     }
     $pathinfo = trim($pathinfo);
     if (!isset($_SERVER["PATH_INFO"])) {
         $_SERVER["PATH_INFO"] = $pathinfo;
     }
     self::$path_info = $pathinfo;
     $get_path_info = function (&$url) {
         static $protocol = null, $protocol_len = 0;
         if (null === $protocol) {
             if (!empty($_SERVER['HTTPS']) && filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN)) {
                 $protocol = 'https://';
                 $protocol_len = 8;
             } else {
                 $protocol = 'http://';
                 $protocol_len = 7;
             }
         }
         $url = strtolower($url);
         # 結尾補/
         if (substr($url, -1) != '/') {
             $url .= '/';
         }
         if (substr($url, 0, $protocol_len) == $protocol) {
             $len = strlen($url);
             if (strtolower(substr($_SERVER["SCRIPT_URI"], 0, $len)) == $url) {
                 # 匹配到項目
                 return '/' . substr($_SERVER["SCRIPT_URI"], $len);
             }
         } else {
             # 開頭補/
             if (substr($url, 0, 1) != '/') {
                 $url = '/' . $url;
             }
             $len = strlen($url);
             if (strtolower(substr(Bootstrap::$path_info, 0, $len)) == $url) {
                 # 匹配到項目
                 return '/' . substr(Bootstrap::$path_info, $len);
             }
         }
         return false;
     };
     # 項目相關設置
     if (isset(self::$config['core']['projects']) && is_array(self::$config['core']['projects']) && self::$config['core']['projects']) {
         # 處理項目
         foreach (self::$config['core']['projects'] as $project => $item) {
             if (!preg_match('#^[a-z0-9_]+$#i', $project)) {
                 continue;
             }
             $admin_url = array();
             if (isset($item['admin_url']) && $item['admin_url']) {
                 if (!is_array($item['admin_url'])) {
                     $item['admin_url'] = array($item['admin_url']);
                 }
                 foreach ($item['admin_url'] as $tmp_url) {
                     if (preg_match('#^http(s)?\\://#i', $tmp_url)) {
                         if (($path_info_admin = $get_path_info($tmp_url)) != false) {
                             self::$project = $project;
//.........這裏部分代碼省略.........
開發者ID:google2013,項目名稱:myqee,代碼行數:101,代碼來源:bootstrap.php

示例2: setup_by_url

 /**
  * 根據URL初始化
  */
 private static function setup_by_url(&$request_mode)
 {
     # 當沒有$_SERVER["SCRIPT_URL"] 時拚接起來
     if (!isset($_SERVER['SCRIPT_URL'])) {
         $tmp_uri = explode('?', $_SERVER['REQUEST_URI'], 2);
         $_SERVER['SCRIPT_URL'] = $tmp_uri[0];
     }
     # 處理BASE_URL
     if (isset(self::$core_config['root_path']) && self::$core_config['root_path']) {
         self::$base_url = rtrim(self::$core_config['root_path'], '/');
     } else {
         if (null === self::$base_url && isset($_SERVER["SCRIPT_NAME"]) && $_SERVER["SCRIPT_NAME"]) {
             $base_url_len = strrpos($_SERVER["SCRIPT_NAME"], '/');
             if (false !== $base_url_len) {
                 $base_url_len += 1;
                 # 截取到最後一個/的位置
                 $base_url = substr($_SERVER["SCRIPT_NAME"], 0, $base_url_len);
                 if (preg_match('#^(.*)/wwwroot/$#', $base_url, $m)) {
                     # 特殊處理wwwroot目錄
                     $base_url = $m[1] . '/';
                     $base_url_len = strlen($base_url);
                 }
                 if (strtolower(substr($_SERVER['REQUEST_URI'], 0, $base_url_len)) == strtolower($base_url)) {
                     self::$base_url = $base_url;
                 }
             }
         }
     }
     # 當沒有$_SERVER["SCRIPT_URI"] 時拚接起來
     if (!isset($_SERVER['SCRIPT_URI'])) {
         $_SERVER['SCRIPT_URI'] = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . (isset($_SERVER['SCRIPT_URL']) ? $_SERVER['SCRIPT_URL'] : $_SERVER["REQUEST_URI"]);
     }
     if (isset($_SERVER['PATH_INFO'])) {
         if (substr($_SERVER['PATH_INFO'], 0, 9) === '/wwwroot/') {
             $pathinfo = substr($_SERVER['PATH_INFO'], 8);
         } else {
             $pathinfo = $_SERVER['PATH_INFO'];
         }
     } else {
         if (isset($_SERVER['REQUEST_URI'])) {
             $request_uri = str_replace('\\', '/', $_SERVER['REQUEST_URI']);
             $root_uri = '/' . ltrim(str_replace('\\', '/', substr($_SERVER['SCRIPT_FILENAME'], strlen($_SERVER['DOCUMENT_ROOT']))), '/');
             $index_file = 'index' . EXT;
             if (substr($root_uri, -strlen($index_file)) == $index_file) {
                 $root_uri = substr($root_uri, 0, -strlen($index_file));
             }
             if ($root_uri && $root_uri != '/') {
                 $request_uri = substr($request_uri, strlen($root_uri));
             }
             list($pathinfo) = explode('?', $request_uri, 2);
             $pathinfo = '/' . ltrim($pathinfo, '/');
         } elseif (isset($_SERVER['PHP_SELF'])) {
             $pathinfo = $_SERVER['PHP_SELF'];
         } elseif (isset($_SERVER['REDIRECT_URL'])) {
             $pathinfo = $_SERVER['REDIRECT_URL'];
         } else {
             $pathinfo = false;
         }
     }
     # 過濾pathinfo傳入進來的服務器默認頁
     if (false !== $pathinfo && ($indexpagelen = strlen(self::$core_config['server_index_page'])) && substr($pathinfo, -1 - $indexpagelen) == '/' . self::$core_config['server_index_page']) {
         $pathinfo = substr($pathinfo, 0, -$indexpagelen);
     }
     $pathinfo = trim($pathinfo);
     if (!isset($_SERVER["PATH_INFO"])) {
         $_SERVER["PATH_INFO"] = $pathinfo;
     }
     self::$path_info = $pathinfo;
     # 處理項目
     foreach (self::$core_config['projects'] as $project => $item) {
         if (!preg_match('#^[a-z0-9_]+$#i', $project)) {
             continue;
         }
         $rest_url = array();
         $admin_url = array();
         if (isset($item['dir']) && $item['dir']) {
             $project_dir = $item['dir'];
         } else {
             $project_dir = $project;
         }
         if (isset($item['url_rest']) && $item['url_rest']) {
             foreach ((array) $item['url_rest'] as $tmp_url) {
                 if (preg_match('#^http(s)?\\://#i', $tmp_url)) {
                     if (($url_path_info = self::_get_pathinfo($tmp_url)) !== false) {
                         self::$project = $project;
                         self::$project_dir = $project_dir;
                         self::$path_info = $url_path_info;
                         self::$base_url = $tmp_url;
                         $request_mode = 'rest';
                         break 2;
                     }
                 } else {
                     # /開頭的後台URL
                     $rest_url[] = $tmp_url;
                 }
             }
         }
//.........這裏部分代碼省略.........
開發者ID:liuyu121,項目名稱:myqee,代碼行數:101,代碼來源:bootstrap.php

示例3: setup


//.........這裏部分代碼省略.........
         self::$base_url = self::$config['core']['base_url'];
     }
     if (isset(self::$config['core']['url']['assets'])) {
         $assets_url = self::$config['core']['url']['assets'];
     } else {
         $assets_url = '/asstes/';
     }
     define('URL_ASSETS', $assets_url);
     unset($assets_url);
     $now_project = null;
     if (IS_CLI) {
         if (isset($_SERVER['OS']) && $_SERVER['OS'] == 'Windows_NT') {
             # 切換到UTF-8編碼顯示狀態
             exec('chcp 65001');
         }
         if (!isset($_SERVER["argv"])) {
             exit('Err Argv');
         }
         $argv = $_SERVER["argv"];
         //$argv[0]為文件名
         if (isset($argv[1])) {
             $project = $argv[1];
             if (isset(self::$config['core']['projects'][$project])) {
                 $now_project = $project;
                 $project = self::$config['core']['projects'][$project];
             } else {
                 $project = false;
             }
         } else {
             $project = false;
         }
         array_shift($argv);
         //將文件名移除
         array_shift($argv);
         //將項目名移除
         self::$path_info = trim(implode('/', $argv));
     } else {
         self::$path_info = self::_get_pathinfo();
         $project_url = false;
         foreach (self::$config['core']['projects'] as $k => &$item) {
             if (!isset($item['url'])) {
                 $item['url'] = array();
             }
             if (!is_array($item['url'])) {
                 $item['url'] = array((string) $item['url']);
             }
             $tmp_pathinfo = self::$path_info;
             foreach ($item['url'] as $index => $u) {
                 if (self::_check_is_this_url($u, self::$path_info)) {
                     $project_url = $u;
                     self::$curren_uri_index = $index;
                     break;
                 }
             }
             if (false !== $project_url) {
                 if (isset($item['url_admin']) && $item['url_admin']) {
                     if (!strpos($item['url_admin'], '://')) {
                         $tmp_pathinfo = self::$path_info;
                     }
                     if (self::_check_is_this_url($item['url_admin'], $tmp_pathinfo)) {
                         self::$path_info = $tmp_pathinfo;
                         self::$is_admin_url = true;
                     }
                 }
                 self::$project_url = $project_url;
                 $project_config = $item;
                 $now_project = $k;
                 break;
             }
         }
     }
     if (!$now_project) {
         if (IS_CLI) {
             # 命令行下執行
             echo 'use:' . CRLF;
             foreach (self::$config['core']['projects'] as $k => $item) {
                 if (isset($item['isuse']) && !$item['isuse']) {
                     continue;
                 }
                 echo "    " . $k . CRLF;
             }
             return true;
         }
         if (isset(self::$config['core']['projects']['default'])) {
             $now_project = 'default';
         } else {
             self::_throw_sys_error_msg(__('not found the project: :project', array(':project' => $now_project)));
         }
     }
     /**
      * 初始項目名
      * @var string
      */
     define('INITIAL_PROJECT_NAME', $now_project);
     self::set_project($now_project);
     # 注冊自動加載類
     spl_autoload_register(array('Bootstrap', 'auto_load'));
     # 加載係統核心
     Core::setup($auto_run);
 }
開發者ID:google2013,項目名稱:myqeecms,代碼行數:101,代碼來源:bootstrap.php


注:本文中的Bootstrap::path_info方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。