本文整理汇总了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;
//.........这里部分代码省略.........
示例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;
}
}
}
//.........这里部分代码省略.........
示例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);
}