本文整理汇总了PHP中Bootstrap::project_dir方法的典型用法代码示例。如果您正苦于以下问题:PHP Bootstrap::project_dir方法的具体用法?PHP Bootstrap::project_dir怎么用?PHP Bootstrap::project_dir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bootstrap
的用法示例。
在下文中一共展示了Bootstrap::project_dir方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
}
}
//.........这里部分代码省略.........
示例2: set_project
/**
* 设置项目
* 可重新设置新项目已实现程序内项目切换,但需谨慎使用
* @param string $project
*/
public static function set_project($project)
{
if (self::$project == $project) {
return true;
}
static $core_config = null;
if (null === $core_config) {
# 记录原始Core配置
$core_config = self::$config['core'];
}
if (!isset($core_config['projects'][$project])) {
self::_throw_sys_error_msg(__('not found the project: :project.', array(':project' => $project)));
}
if (!$core_config['projects'][$project]['isuse']) {
self::_throw_sys_error_msg(__('the project: :project is not open.', array(':project' => '$project')));
}
# 获取core里项目配置
$project_config = $core_config['projects'][$project];
# 项目路径
$project_dir = realpath(DIR_PROJECT . $project_config['dir']);
if (!$project_dir || !is_dir($project_dir)) {
self::_throw_sys_error_msg(__('the project dir :dir is not exist.', array(':dir' => $project_config['dir'])));
}
$project_dir .= DS;
self::$project_dir = $project_dir;
# 记录所有项目设置,当切换回项目时,使用此设置还原
static $all_prjects_setting = array();
if (self::$project) {
# 记录上一个项目设置
$all_prjects_setting[self::$project] = array('config' => self::$config, 'project_config' => self::$project_config, 'include_path' => self::$include_path, 'file_list' => self::$file_list);
}
# 设为当前项目
self::$project = $project;
# 记录debug信息
if (class_exists('Core', false)) {
Core::debug()->info('程序已切换到了新项目:' . $project);
}
if (isset($all_prjects_setting[$project])) {
# 还原配置
self::$config = $all_prjects_setting[$project]['config'];
self::$project_config = $all_prjects_setting[$project]['project_config'];
self::$include_path = $all_prjects_setting[$project]['include_path'];
self::$file_list = $all_prjects_setting[$project]['file_list'];
} else {
# 合并配置
$config = $core_config['projects'][$project] + self::$config['core'];
# 读取项目配置
if (is_file($project_dir . 'config' . EXT)) {
self::_include_config_file($config, $project_dir . 'config' . EXT);
}
# 读取DEBUG配置
if (isset(self::$config['core']['debug_config']) && self::$config['core']['debug_config'] && is_file($project_dir . 'debug.config' . EXT)) {
self::_include_config_file($config, $project_dir . 'debug.config' . EXT);
}
# 清理项目配置
self::$project_config = $config;
self::$config = array('core' => &self::$project_config);
unset($config);
# Builder构建,处理 self::$file_list
if (self::$project_config['use_bulider'] === 'auto') {
if (IS_DEBUG) {
$usebulider = false;
} else {
$usebulider = true;
}
} else {
$usebulider = (bool) self::$project_config['use_bulider'];
}
$project_filelist = DIR_BULIDER . self::$project . DS . 'project_all_files_list' . EXT;
if (true === $usebulider && !IS_CLI && is_file($project_filelist)) {
# 读取文件列表
self::_include_config_file(self::$file_list, $project_filelist);
}
# 设置包含目录
self::$include_path = self::get_project_include_path($project);
}
if (isset(self::$project_config['error_reporting'])) {
error_reporting(self::$project_config['error_reporting']);
}
# 时区设置
if (isset(self::$project_config['timezone'])) {
date_default_timezone_set(self::$project_config['timezone']);
}
if (class_exists('Core', false)) {
# 输出调试信息
if (IS_DEBUG) {
Core::debug()->group('当前加载目录');
foreach (self::$include_path as $value) {
Core::debug()->log(Core::debug_path($value));
}
Core::debug()->groupEnd();
}
Core::ini_library();
}
}