if ($this->shouldRecompile($manifest, $providers)) {$manifest = $this->compileManifest($providers);}
如果bootstrap/cache/services.php文件不存在 则重新编译文件
重新编译services.php文件
封装一个数组, 如果provider是急加载 则 $manifest[‘eager’][] =
p
r
o
v
i
d
e
r
;
如
果
是
延
迟
加
载
则
‘
provider; 如果是延迟加载则 `
provider;如果是延迟加载则‘manifest[‘deferred’][$service] = $provider;
m
a
n
i
f
e
s
t
[
′
w
h
e
n
′
]
[
manifest['when'][
manifest[′when′][provider] = $instance->when();`
将上面的数组重新写入bootstrap/cache/services.php
foreach ($manifest['eager'] as $provider) { $this->app->register($provider);} 注册eager服务
if (($registered = $this->getProvider($provider)) && ! $force) {return $registered;} 如果已经注册了,则直接返回
if (is_string($provider)) {$provider = $this->resolveProvider($provider);} 实例化provider
if (method_exists($provider, 'register')) {$provider->register();} 执行provider实例的register方法
// Illuminate\Foundation\Application /**
* Register all of the configured providers.
*
* @return void
*/publicfunctionregisterConfiguredProviders(){$providers= Collection::make($this->config['app.providers'])->partition(function($provider){return Str::startsWith($provider,'Illuminate\\');});$providers->splice(1,0,[$this->make(PackageManifest::class)->providers()]);(newProviderRepository($this,newFilesystem,$this->getCachedServicesPath()))->load($providers->collapse()->toArray());}/**
* Register a service provider with the application.
*
* @param \Illuminate\Support\ServiceProvider|string $provider
* @param array $options
* @param bool $force
* @return \Illuminate\Support\ServiceProvider
*/publicfunctionregister($provider,$options=[],$force=false){if(($registered=$this->getProvider($provider))&&!$force){return$registered;}// If the given "provider" is a string, we will resolve it, passing in the// application instance automatically for the developer. This is simply// a more convenient way of specifying your service provider classes.if(is_string($provider)){$provider=$this->resolveProvider($provider);}if(method_exists($provider,'register')){$provider->register();}$this->markAsRegistered($provider);// If the application has already booted, we will call this boot method on// the provider class so it has an opportunity to do its boot logic and// will be ready for any usage by this developer's application logic.if($this->booted){$this->bootProvider($provider);}return$provider;}/**
* Mark the given provider as registered.
*
* @param \Illuminate\Support\ServiceProvider $provider
* @return void
*/protectedfunctionmarkAsRegistered($provider){$this->serviceProviders[]=$provider;$this->loadedProviders[get_class($provider)]=true;}/**
* Add an array of services to the application's deferred services.
*
* @param array $services
* @return void
*/publicfunctionaddDeferredServices(array$services){$this->deferredServices=array_merge($this->deferredServices,$services);}// Illuminate\Foundation\ProviderRepository/**
* Register the application service providers.
*
* @param array $providers
* @return void
*/publicfunctionload(array$providers){$manifest=$this->loadManifest();// First we will load the service manifest, which contains information on all// service providers registered with the application and which services it// provides. This is used to know which services are "deferred" loaders.if($this->shouldRecompile($manifest,$providers)){$manifest=$this->compileManifest($providers);}// Next, we will register events to load the providers for each of the events// that it has requested. This allows the service provider to defer itself// while still getting automatically loaded when a certain event occurs.foreach($manifest['when']as$provider=>$events){$this->registerLoadEvents($provider,$events);}// We will go ahead and register all of the eagerly loaded providers with the// application so their services can be registered with the application as// a provided service. Then we will set the deferred service list on it.foreach($manifest['eager']as$provider){$this->app->register($provider);}$this->app->addDeferredServices($manifest['deferred']);}/**
* Compile the application service manifest file.
*
* @param array $providers
* @return array
*/protectedfunctioncompileManifest($providers){// The service manifest should contain a list of all of the providers for// the application so we can compare it on each request to the service// and determine if the manifest should be recompiled or is current.$manifest=$this->freshManifest($providers);foreach($providersas$provider){$instance=$this->createProvider($provider);// When recompiling the service manifest, we will spin through each of the// providers and check if it's a deferred provider or not. If so we'll// add it's provided services to the manifest and note the provider.if($instance->isDeferred()){foreach($instance->provides()as$service){$manifest['deferred'][$service]=$provider;}$manifest['when'][$provider]=$instance->when();}// If the service providers are not deferred, we will simply add it to an// array of eagerly loaded providers that will get registered on every// request to this application instead of "lazy" loading every time.else{$manifest['eager'][]=$provider;}}return$this->writeManifest($manifest);}