Beispiel #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>';
             }
         });
     }
 }
Beispiel #2
0
 /**
  * 系统启动
  *
  * @param boolean $auto_execute 是否直接运行
  */
 public static function setup($auto_execute = true)
 {
     static $run = null;
     if (null === $run) {
         $run = true;
         Core::$charset = Core::$config['charset'];
         if (!IS_CLI) {
             # 输出powered by信息
             $x_powered_by = isset(Core::$config['hide_x_powered_by_header']) && Core::$config['hide_x_powered_by_header'] ? Core::$config['hide_x_powered_by_header'] : false;
             if (is_string($x_powered_by)) {
                 $str = 'X-Powered-By: ' . trim(str_replace(array("\r", "\n"), '', $x_powered_by));
             } else {
                 if (!$x_powered_by) {
                     $str = 'X-Powered-By: PHP/' . PHP_VERSION . ' MyQEE/' . Core::VERSION . '(' . Core::RELEASE . ')';
                 } else {
                     $str = null;
                 }
             }
             if ($str) {
                 header($str);
             }
         }
         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) {
             # 初始化 HttpIO 对象
             HttpIO::setup();
         }
         # 注册输出函数
         register_shutdown_function(array('Core', '_output_body'));
         if (true === IS_SYSTEM_MODE) {
             if (false === Core::check_system_request_allow()) {
                 # 内部请求验证不通过
                 Core::show_500('system request hash error');
             }
         }
         if (!defined('URL_ASSETS')) {
             /**
              * 静态文件URL地址前缀
              *
              * @var string
              */
             define('URL_ASSETS', rtrim(Core::config('url.assets', Core::url('/assets/')), '/') . '/');
         }
         if (IS_DEBUG && isset($_REQUEST['debug']) && class_exists('Profiler', true)) {
             Profiler::setup();
         }
         if (IS_DEBUG && !IS_CLI) {
             Core::debug()->info('SERVER IP:' . $_SERVER["SERVER_ADDR"] . (function_exists('php_uname') ? '. SERVER NAME:' . php_uname('a') : ''));
             if (Core::$project) {
                 Core::debug()->info('project: ' . Core::$project);
             }
             if (IS_ADMIN_MODE) {
                 Core::debug()->info('admin mode');
             }
             if (IS_REST_MODE) {
                 Core::debug()->info('RESTFul mode');
             }
             Core::debug()->group('include path');
             foreach (Core::include_path() as $value) {
                 Core::debug()->log(Core::debug_path($value));
             }
             Core::debug()->groupEnd();
         }
     }
     /**
      * 系统加载完毕时间
      */
     define('SYSTEM_LOADED_TIME', microtime(1));
     if ($auto_execute) {
         Core::run();
     }
 }
Beispiel #3
0
 /**
  * 系统启动
  * @param string $pathinfo
  */
 public static function setup($auto_run = true)
 {
     static $run = null;
     if (true === $run) {
         if ($auto_run) {
             Core::run();
         }
         return;
     }
     $run = true;
     Core::$charset = Core::$config['core']['charset'];
     # 注销Bootstrap的自动加载类
     spl_autoload_unregister(array('Bootstrap', 'auto_load'));
     # 注册自动加载类
     spl_autoload_register(array('Core', 'auto_load'));
     if (!IS_CLI) {
         # 输出powered by信息
         header('X-Powered-By: PHP/' . PHP_VERSION . ' MyQEE/' . Core::VERSION);
     }
     # 检查Bootstrap版本
     if (version_compare(Bootstrap::VERSION, '1.9', '<')) {
         Core::show_500('系统Bootstrap版本太低,请先升级Bootstrap。');
         exit;
     }
     Core::debug()->info('当前项目:' . INITIAL_PROJECT_NAME);
     if (IS_DEBUG) {
         Core::debug()->group('系统加载目录');
         foreach (Core::$include_path as $value) {
             Core::debug()->log(Core::debug_path($value));
         }
         Core::debug()->groupEnd();
     }
     if ((IS_CLI || IS_DEBUG) && class_exists('ErrException', true)) {
         # 注册脚本
         register_shutdown_function(array('ErrException', 'shutdown_handler'));
         # 捕获错误
         set_exception_handler(array('ErrException', 'exception_handler'));
         set_error_handler(array('ErrException', '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());
     }
     # 初始化 HttpIO 对象
     HttpIO::setup();
     # 注册输出函数
     register_shutdown_function(array('Core', 'output'));
     # 初始化类库
     Core::ini_library();
     if (true === IS_SYSTEM_MODE) {
         if (false === Core::check_system_request_allow()) {
             # 内部请求验证不通过
             Core::show_500('system request hash error');
         }
     }
     if (IS_DEBUG && isset($_REQUEST['debug']) && class_exists('Profiler', true)) {
         Profiler::setup();
     }
     if ($auto_run) {
         Core::run();
     }
 }