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);
}
```