Пример #1
0
 public static function setup()
 {
     static $run = null;
     if (!$run) {
         /**
          * 是否管理模式
          *
          * @var boolean
          */
         \define('IS_ADMIN_MODE', false);
         $is_online_debug = function () {
             if (!isset($_COOKIE['_debug_open'])) {
                 return false;
             }
             if (!isset(\Bootstrap::$config['core']['debug_open_password'])) {
                 return false;
             }
             if (!\is_array(\Bootstrap::$config['core']['debug_open_password'])) {
                 \Bootstrap::$config['core']['debug_open_password'] = array((string) \Bootstrap::$config['core']['debug_open_password']);
             }
             foreach (\Bootstrap::$config['core']['debug_open_password'] as $item) {
                 if ($_COOKIE['_debug_open'] == \Bootstrap::get_debug_hash($item)) {
                     return true;
                 }
             }
             return false;
         };
         if ($is_online_debug()) {
             $local_debug = true;
         } elseif (isset(\Bootstrap::$config['core']['local_debug_cfg']) && \Bootstrap::$config['core']['local_debug_cfg']) {
             if (\function_exists('\\get_cfg_var')) {
                 $local_debug = \get_cfg_var(\Bootstrap::$config['core']['local_debug_cfg']) ? true : false;
             } else {
                 $local_debug = false;
             }
         } else {
             $local_debug = false;
         }
         /**
          * 是否AJAX请求
          *
          * @var boolean
          */
         \define('IS_DEBUG', $local_debug);
         if (\IS_DEBUG && isset(\Bootstrap::$config['core']['libraries']['debug']) && \is_array(\Bootstrap::$config['core']['libraries']['debug']) && \Bootstrap::$config['core']['libraries']['debug']) {
             foreach (\Bootstrap::$config['core']['libraries']['debug'] as $lib) {
                 static::import_library($lib);
             }
         }
         static::$project =& \Bootstrap::$project;
         static::$include_puth =& \Bootstrap::$include_path;
         static::$charset = \Bootstrap::$config['core']['charset'];
         # 检查\Bootstrap版本
         if (\version_compare(\Bootstrap::VERSION, '2.0', '<')) {
             static::show_500('系统\\Bootstrap版本太低,请先升级\\Bootstrap。');
             exit;
         }
         if ((\IS_CLI || \IS_DEBUG) && \class_exists('\\DevException', true)) {
             # 注册脚本
             \register_shutdown_function(array('\\DevException', 'shutdown_handler'));
             # 捕获错误
             \set_exception_handler(array('\\DevException', 'exception_handler'));
             \set_error_handler(array('\\DevException', 'error_handler'), \error_reporting());
         } else {
             # 注册脚本
             \register_shutdown_function(array('\\Core', 'shutdown_handler'));
             # 捕获错误
             \set_exception_handler(array('\\Core', 'exception_handler'));
             \set_error_handler(array('\\Core', 'error_handler'), \error_reporting());
         }
         if (!\IS_CLI) {
             \header('X-Powered-By: PHP/' . \PHP_VERSION . ', MyQEE/' . static::VERSION);
             \HttpIO::setup();
         }
         if (\IS_SYSTEM_MODE && false === static::check_system_request_allow()) {
             # 内部请求验证不通过
             static::show_500('system request hash error');
         }
     }
     if (\IS_DEBUG && isset($_REQUEST['debug']) && \class_exists('\\Debug_Profiler', true)) {
         \Debug_Profiler::setup();
     }
     if (!\IS_CLI) {
         \register_shutdown_function(function () {
             \HttpIO::send_headers();
             # 输出内容
             echo \HttpIO::$body;
             if ($_GET['test']) {
                 //TODO///////TEST
                 echo '<br><pre>';
                 echo \microtime(1) - \START_TIME;
                 echo "\n";
                 echo (\memory_get_usage() - \START_MEMORY) / 1024 . 'kb';
                 echo "\n";
                 echo \memory_get_usage() / 1024 . 'kb';
                 echo "\n";
                 echo '<br><hr>include path<br>';
                 \print_r(\Bootstrap::$include_path);
                 \print_r(\get_included_files());
                 echo '</pre>';
             }
         });
     }
 }