Laravel源码分析---Application类实例化(2)

本文继续上篇分析Laravel的Application类实例化过程,重点讲解注册基本服务绑定和初始化函数。内容涉及服务提供者的注册、过滤实例、事件对象绑定以及bind函数的使用,揭示了Laravel内部如何管理和实例化服务。
摘要由CSDN通过智能技术生成

    接着第一篇之后,现在轮到执行注册基本服务绑定

        $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))
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值