public
static
function
setup(
$auto_execute
= true)
{
static
$run
= null;
if
(!
$run
)
{
$run
= true;
# PHP5.3 支持 composer 的加载
if
(HAVE_NS &&
is_file
(DIR_VENDOR.
'autoload-for-myqee.php'
))
{
try
{
require
DIR_VENDOR.
'autoload-for-myqee.php'
;
}
catch
(Exception
$e
)
{
self::_show_error(
$e
->getMessage());
}
$composer
= true;
}
else
{
$composer
= false;
}
define(
'IS_COMPOSER_LOADED'
,
$composer
);
# 注册自动加载类
spl_autoload_register(
array
(
'Bootstrap'
,
'auto_load'
), true, true);
# 读取配置
if
(!
is_file
(DIR_SYSTEM .
'config'
. EXT))
{
self::_show_error(__(
'Please rename the file config.new:EXT to config:EXT'
,
array
(
':EXT'
=>EXT)));
}
__include_config_file(self::
$core_config
, DIR_SYSTEM .
'config'
. EXT);
# 本地调试模式
if
(isset(self::
$core_config
[
'local_debug_cfg'
]) && self::
$core_config
[
'local_debug_cfg'
])
{
# 判断是否开启了本地调试
if
(function_exists(
'get_cfg_var'
))
{
$open_debug
= get_cfg_var(self::
$core_config
[
'local_debug_cfg'
])?1:0;
}
else
{
$open_debug
= 0;
}
}
else
{
$open_debug
= 0;
}
# 在线调试
if
(self::_is_online_debug())
{
$open_debug
= 1<<1 |
$open_debug
;
}
define(
'IS_DEBUG'
,
$open_debug
);
if
(
$open_debug
&& isset(
$_REQUEST
[
'debug'
]))
{
$open_profiler
= true;
}
else
{
$open_profiler
= false;
}
define(
'IS_OPEN_PROFILER'
,
$open_profiler
);
# Runtime配置
if
(!isset(self::
$core_config
[
'runtime_config'
]))
{
self::
$core_config
[
'runtime_config'
] =
''
;
}
else
if
(self::
$core_config
[
'runtime_config'
] && !preg_match(
'#^[a-z0-9_]+$#'
, self::
$core_config
[
'runtime_config'
]))
{
self::
$core_config
[
'runtime_config'
] =
''
;
}
if
(self::
$core_config
[
'runtime_config'
])
{
$runtime_file
= DIR_SYSTEM .
'config.'
. self::
$core_config
[
'runtime_config'
] .
'.runtime'
. EXT;
# 读取配置
if
(
is_file
(
$runtime_file
))
{
__include_config_file(self::
$core_config
,
$runtime_file
);
}
}
if
(!IS_CLI)
{
# 输出文件头
header(
'Content-Type: text/html;charset='
. self::
$core_config
[
'charset'
]);
}
if
(isset(self::
$core_config
[
'error_reporting'
]))
{
@
error_reporting
(self::
$core_config
[
'error_reporting'
]);
}
if
(isset(self::
$core_config
[
'timezone'
]))
{
@date_default_timezone_set(self::
$core_config
[
'timezone'
]);
}
global
$project
,
$admin_mode
,
$rest_mode
;
if
(IS_SYSTEM_MODE)
{
if
(isset(
$_SERVER
[
'HTTP_X_MYQEE_SYSTEM_PROJECT'
]))
{
$project
=
$_SERVER
[
'HTTP_X_MYQEE_SYSTEM_PROJECT'
];
}
if
(isset(
$_SERVER
[
'HTTP_X_MYQEE_SYSTEM_PATHINFO'
]))
{
self::
$path_info
=
$_SERVER
[
'HTTP_X_MYQEE_SYSTEM_PATHINFO'
];
}
if
(isset(
$_SERVER
[
'HTTP_X_MYQEE_SYSTEM_ISADMIN'
]) &&
$_SERVER
[
'HTTP_X_MYQEE_SYSTEM_ISADMIN'
])
{
$request_mode
=
'admin'
;
}
elseif
(isset(
$_SERVER
[
'HTTP_X_MYQEE_SYSTEM_ISREST'
]) &&
$_SERVER
[
'HTTP_X_MYQEE_SYSTEM_ISREST'
])
{
$request_mode
=
'rest'
;
}
}
if
(isset(
$admin_mode
) &&
$admin_mode
)
{
$request_mode
=
'admin'
;
}
elseif
(isset(
$rest_mode
) &&
$rest_mode
)
{
$request_mode
=
'rest'
;
}
if
(isset(
$project
) &&
$project
)
{
$project
= (string)
$project
;
if
(!isset(self::
$core_config
[
'projects'
][
$project
]))
{
self::_show_error(__(
'not found the project: :project'
,
array
(
':project'
=>
$project
)));
}
self::
$project
=
$project
;
}
else
{
if
(IS_CLI)
{
if
(!isset(
$_SERVER
[
"argv"
]))
{
exit
(
'Err Argv'
);
}
$argv
=
$_SERVER
[
"argv"
];
if
(isset(
$argv
[1]) &&
$argv
[1] && isset(self::
$core_config
[
'projects'
][
$argv
[1]]))
{
self::
$project
=
$argv
[1];
}
array_shift
(
$argv
);
array_shift
(
$argv
);
self::
$path_info
= trim(implode(
'/'
,
$argv
));
unset(
$argv
);
}
else
{
$temp_mode
=
''
;
self::setup_by_url(
$temp_mode
);
if
(!
$request_mode
)
{
$request_mode
=
$temp_mode
;
}
}
}
if
(isset(self::
$core_config
[
'projects'
][self::
$project
][
'isuse'
]) && !self::
$core_config
[
'projects'
][self::
$project
][
'isuse'
])
{
self::_show_error(__(
'the project: :project is not open.'
,
array
(
':project'
=>self::
$project
)));
}
define(
'INITIAL_PROJECT_NAME'
, self::
$project
);
if
(!defined(
'IS_ADMIN_MODE'
))define(
'IS_ADMIN_MODE'
, (
$request_mode
==
'admin'
)?true:false);
if
(!defined(
'IS_REST_MODE'
))define(
'IS_REST_MODE'
, (
$request_mode
==
'rest'
)?true:false);
$project_dir
= DIR_PROJECT . self::
$project_dir
. DS;
if
(!
is_dir
(
$project_dir
))
{
self::_show_error(__(
'not found the project: :project'
,
array
(
':project'
=> self::
$project
)));
}
self::
$include_path
[
'project'
] =
array
(self::
$project
=>
$project_dir
);
# 加载类库
self::reload_all_libraries();
}
Core::setup(
$auto_execute
);
}