接着第一篇之后,现在轮到执行注册基本服务绑定
$this->registerBaseBindings();
/**
* Register the basic bindings into the container.
*
* @return void
*/
protected function registerBaseBindings()
{
//设置分享实例
static::setInstance($this);
//绑定Application实体类到instances['app']数组
$this->instance('app', $this);
//绑定Application实体类到instances['Illuminate\\Container\\Container']数组
$this->instance(Container::class, $this);
//绑定文件系统instance['Illuminate\Foundation\PackageManifest']
$this->instance(PackageManifest::class, new PackageManifest(
new Filesystem, $this->basePath(), $this->getCachedPackagesPath()
));
}
然后看看PackageManifest
的初始化函数
/**
* Create a new package manifest instance.
*
* @param \Illuminate\Filesystem\Filesystem $files
* @param string $basePath
* @param string $manifestPath
* @return void
*/
public function __construct(Filesystem $files, $basePath, $manifestPath)
{
$this->files = $files;
$this->basePath = $basePath;
$this->manifestPath = $manifestPath;
$this->vendorPath = $basePath.'/vendor';
}
这个会新建一个\Illuminate\Filesystem\Filesystem
传递进来,然后绑定
$this->basePath = '/data/project/queue'
$this->manifestPath = '/data/project/queue/bootstrap/cache/packages.php'
$this->vendorPath = '/data/project/queue/vendor'
这样子就将registerBaseBindings
全部注册完成了
$this->registerBaseServiceProviders();
/**
* Register all of the base service providers.
*
* @return void
*/
protected function registerBaseServiceProviders()
{
$this->register(new EventServiceProvider($this))