Example #1
0
 public function bootstrap()
 {
     define('IS_CLI', PHP_SAPI == 'cli');
     define('NOW', $_SERVER['REQUEST_TIME']);
     define('__ROOT__', IS_CLI ? '' : trim('http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']), '/\\'));
     IS_CLI or define('IS_GET', $_SERVER['REQUEST_METHOD'] == 'GET');
     IS_CLI or define('IS_POST', $_SERVER['REQUEST_METHOD'] == 'POST');
     IS_CLI or define('IS_DELETE', $_SERVER['REQUEST_METHOD'] == 'DELETE' ? TRUE : isset($_POST['_method']) && $_POST['_method'] == 'DELETE');
     IS_CLI or define('IS_PUT', $_SERVER['REQUEST_METHOD'] == 'PUT' ? TRUE : isset($_POST['_method']) && $_POST['_method'] == 'PUT');
     IS_CLI or define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
     IS_CLI or define('IS_WEIXIN', isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== FALSE);
     IS_CLI or define('__URL__', trim('http://' . $_SERVER['HTTP_HOST'] . '/' . trim($_SERVER['REQUEST_URI'], '/\\'), '/'));
     IS_CLI or define("__HISTORY__", isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : '');
     //加载服务配置项
     $servers = (require __DIR__ . '/service.php');
     $config = (require ROOT_PATH . '/system/config/service.php');
     $servers['providers'] = array_merge($config['providers'], $servers['providers']);
     $servers['facades'] = array_merge($config['facades'], $servers['facades']);
     $this->servers = $servers;
     //自动加载系统服务
     Loader::register([$this, 'autoload']);
     //绑定核心服务提供者
     $this->bindServiceProvider();
     //添加初始实例
     $this->instance('App', $this);
     //设置外观类APP属性
     ServiceFacade::setFacadeApplication($this);
     //定义错误/异常处理
     Error::bootstrap();
     //导入类库别名
     Loader::addMap(c('app.alias'));
     //自动加载文件
     Loader::autoloadFile();
     //启动服务
     $this->boot();
     //CLI模式
     $this->cli();
     //应用开始中间件
     \Middleware::exe('app_start');
     //解析路由
     Route::dispatch();
     //记录日志
     Log::save();
     //中间件
     \Middleware::exe('app_end');
 }