Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to the framework to customize service providers loading process #52549

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/Illuminate/Contracts/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,20 @@ public function isDownForMaintenance();
/**
* Register all of the configured providers.
*
* @param \Illuminate\Foundation\ProviderRepository|null $providerRepository
* @return void
*/
public function registerConfiguredProviders();
public function registerConfiguredProviders($providerRepository);

/**
* Register a service provider with the application.
*
* @param \Illuminate\Support\ServiceProvider|string $provider
* @param bool $force
* @param bool $boot
* @return \Illuminate\Support\ServiceProvider
*/
public function register($provider, $force = false);
public function register($provider, $force = false, $boot = true);

/**
* Register a deferred provider and service.
Expand All @@ -160,6 +162,14 @@ public function resolveProvider($provider);
*/
public function boot();

/**
* Boot the given service provider.
*
* @param \Illuminate\Support\ServiceProvider $provider
* @return void
*/
public function bootProvider($provider);

/**
* Register a new boot listener.
*
Expand Down
18 changes: 11 additions & 7 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Env;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use RuntimeException;
Expand Down Expand Up @@ -830,17 +829,21 @@ public function registered($callback)
/**
* Register all of the configured providers.
*
* @param \Illuminate\Foundation\ProviderRepository|null $providerRepository
* @return void
*/
public function registerConfiguredProviders()
public function registerConfiguredProviders($providerRepository = null)
{
$providers = Collection::make($this->make('config')->get('app.providers'))
->partition(fn ($provider) => str_starts_with($provider, 'Illuminate\\'));

$providers->splice(1, 0, [$this->make(PackageManifest::class)->providers()]);

(new ProviderRepository($this, new Filesystem, $this->getCachedServicesPath()))
->load($providers->collapse()->toArray());
if ($providerRepository == null) {
$providerRepository = new ProviderRepository($this, new Filesystem, $this->getCachedServicesPath());
}

$providerRepository->load($providers->collapse()->toArray());

$this->fireAppCallbacks($this->registeredCallbacks);
}
Expand All @@ -850,9 +853,10 @@ public function registerConfiguredProviders()
*
* @param \Illuminate\Support\ServiceProvider|string $provider
* @param bool $force
* @param bool $boot
* @return \Illuminate\Support\ServiceProvider
*/
public function register($provider, $force = false)
public function register($provider, $force = false, $boot = true)
{
if (($registered = $this->getProvider($provider)) && ! $force) {
return $registered;
Expand Down Expand Up @@ -889,7 +893,7 @@ public function register($provider, $force = false)
// 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->isBooted()) {
if ($this->isBooted() && $boot) {
$this->bootProvider($provider);
}

Expand Down Expand Up @@ -1111,7 +1115,7 @@ public function boot()
* @param \Illuminate\Support\ServiceProvider $provider
* @return void
*/
protected function bootProvider(ServiceProvider $provider)
public function bootProvider($provider)
{
$provider->callBootingCallbacks();

Expand Down
Loading