选择语言 :

 Bootstrap::setup

系统初始化

null Bootstrap::setup( [ boolean $auto_execute = bool true ] )

参数列表

参数 类型 描述 默认值
$auto_execute boolean 是否自动运行控制器 bool true
File: ./core/bootstrap.php
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;
        }

        /**
         * 是否加载了Composer
         *
         * @var boolean
         */
        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;
        }

        /**
         * 是否开启DEBUG模式
         *
         * 开启远程debug方式:访问 `/opendebugger` 页面,会看到有要输入调试开启账号和密码,这个配置在 `config.php` 的 `$config['debug_open_password']` 中
         *
         *     if (IS_DEBUG>>1)
         *     {
         *         //开启了在线调试
         *     }
         *
         *     if (IS_DEBUG & 1)
         *     {
         *         //本地调试打开
         *     }
         *
         *     if (IS_DEBUG)
         *     {
         *         // 开启了调试
         *     }
         *
         * @var int
         */
        define('IS_DEBUG', $open_debug);

        if ($open_debug && isset($_REQUEST['debug']))
        {
            $open_profiler = true;
        }
        else
        {
            $open_profiler = false;
        }

        /**
         * 是否开启分析器
         *
         * 只有 DEBUG 打开时,IS_OPEN_PROFILER 才有可能被打开,打开方法:当打开 DEBUG 后,在地址栏GET参数中加入 `debug=yes` 访问
         *
         * @var boolean
         */
        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']);
        }


        // 获取全局$project变量
        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)
        {
            // RestFul模式
            $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"];

                //$argv[0]为文件名
                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)));
        }

        /**
         * 初始项目名
         *
         * @var string
         */
        define('INITIAL_PROJECT_NAME', self::$project);

        /**
         * 是否后台模式
         *
         * @var boolean
         */
        if (!defined('IS_ADMIN_MODE'))define('IS_ADMIN_MODE', ($request_mode=='admin')?true:false);

        /**
         * 是否RestFul模式
         *
         * @var boolean
         */
        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);
}