ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
thinkphp6核心分析 https://learnku.com/users/27146/articles?page=2](https://learnku.com/users/27146/articles?page=2 ## 实例化http应用 在入口文件中是通过App类来实例化http应用的。`$http = (new App())->http`。App类是继承Container容器类。则可以通过容器的方式对http进行实例化。先是初始化App类。设置了项目的类库目录。并将自定义的容器标识绑定到容器。 ``` public function __construct(string $rootPath = ''){ // 系统核心框架目录 $this->thinkPath = dirname(__DIR__) . DIRECTORY_SEPARATOR; // 应用根目录 $this->rootPath = $rootPath ? rtrim($rootPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : $this->getDefaultRootPath(); // app目录 $this->appPath = $this->rootPath . 'app' . DIRECTORY_SEPARATOR; // 运行时文件 runtime 目录 $this->runtimePath = $this->rootPath . 'runtime' . DIRECTORY_SEPARATOR; // 绑定标识到容器 if (is_file($this->appPath . 'provider.php')) { $this->bind(include $this->appPath . 'provider.php'); } // 设置容器对象实例 static::setInstance($this); // 设置容器中的对象实例 $this->instance('app', $this); $this->instance('think\Container', $this); } ```