选择语言 :

 Bootstrap::setup

系统初始化

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

参数列表

参数 类型 描述 默认值
$auto_execute boolean 是否自动运行控制器 bool true
File: ./core/bootstrap.php
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
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);
}