laravel5.5简单聊聊\Illuminate\Foundation\Bootstrap\BootProviders::class做了什么

场景

  • laravel在处理http request 之前启动了几个核心的bootstrap class, 下面简单聊聊\Illuminate\Foundation\Bootstrap\BootProviders::class 做了哪些功能

源码分析

  • public function bootstrap(Application $app){$app->boot();} 本质上执行的是service container boot function
  • $this->fireAppCallbacks($this->bootingCallbacks); 执行boot之前的回调函数
  • array_walk($this->serviceProviders, function ($p) {$this->bootProvider($p);}); 调用所有eager provider 的boot function
    • if (method_exists($provider, 'boot')) {return $this->call([$provider, 'boot']);}
  • $this->fireAppCallbacks($this->bootedCallbacks); 执行 booted之后回调函数

小结

  • \Illuminate\Foundation\Bootstrap\BootProviders::class 做的事情比较简单, 执行boot之前之后的两个回调函数, 以及调用eager provider 的boot function

源码

// Illuminate\Foundation\Bootstrap\BootProviders
class BootProviders
{
    /**
     * Bootstrap the given application.
     *
     * @param  \Illuminate\Contracts\Foundation\Application  $app
     * @return void
     */
    public function bootstrap(Application $app)
    {
        $app->boot();
    }
}

// Illuminate\Foundation\Application 

    /**
     * Boot the application's service providers.
     *
     * @return void
     */
    public function boot()
    {
        if ($this->booted) {
            return;
        }

        // Once the application has booted we will also fire some "booted" callbacks
        // for any listeners that need to do work after this initial booting gets
        // finished. This is useful when ordering the boot-up processes we run.
        $this->fireAppCallbacks($this->bootingCallbacks);

        array_walk($this->serviceProviders, function ($p) {
            $this->bootProvider($p);
        });

        $this->booted = true;

        $this->fireAppCallbacks($this->bootedCallbacks);
    }

    /**
     * Boot the given service provider.
     *
     * @param  \Illuminate\Support\ServiceProvider  $provider
     * @return mixed
     */
    protected function bootProvider(ServiceProvider $provider)
    {
        if (method_exists($provider, 'boot')) {
            return $this->call([$provider, 'boot']);
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值