Skip to content

[9.x] Removes core service providers from the skeleton #41998

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

Closed
wants to merge 1 commit into from
Closed

[9.x] Removes core service providers from the skeleton #41998

wants to merge 1 commit into from

Conversation

andriihorpenko
Copy link

@andriihorpenko andriihorpenko commented Apr 15, 2022

This PR allows removing core service providers from the config/app.php from the skeleton. It implements same design decisions Nuno and Taylor used in the similar PR regarding core class aliases (#40062).

The motivation is exactly the same — these classes are rarely modified by the majority of users, so they can find their new home in the core itself.

An example below shows what the future iteration of the skeleton may look like:

'providers' => ServiceProvider::defaultProviders()->merge([
    App\Providers\AppServiceProvider::class,
    App\Providers\AuthServiceProvider::class,
    // App\Providers\BroadcastServiceProvider::class,
    App\Providers\EventServiceProvider::class,
    App\Providers\RouteServiceProvider::class,

    // ...
])->toArray(),

As this is presumably not a breaking change (existing applications may opt for this way of defining service providers only by manually changing the config file), this PR is targeting 9.x branch, but will gladly switch to master if required.

Allows removing core `app.providers` from the skeleton
Merges configurations
Adds `ServiceProvider::defaultProviders`
@crynobone
Copy link
Member

  • How do you swap any of core service providers with custom class?
  • How do you remove any of core service providers?

@andriihorpenko
Copy link
Author

andriihorpenko commented Apr 15, 2022

@crynobone, as I mentioned, this change is great for the majority of users who rarely/never touch this portion of the config. However, if you need more refined control over this — you can either copy the whole default section or use provided examples below.

How do you swap any of core service providers with custom class?

Here we have two options: use the full power of collections or simply copy defaults. This is how it may look like by using collections:

...
->map(fn($provider) => match ($provider) {
    CookieServiceProvider::class => FooServiceProvider::class,
    default => $provider,
})->toArray(),

How do you remove any of core service providers?

We can use the diff method which will exclude specified classes from the final collection. I was initially using it to exclude BroadcastServiceProvider as an example, but the current variant looks cleaner as for a skeleton.

...
->diff([
    CookieServiceProvider::class,
])->toArray(),

@GrahamCampbell
Copy link
Member

I prefer what we already have. It is much better DX than what is proposed here.

@andriihorpenko
Copy link
Author

I wonder why Nuno and Taylor applied that cleanup for core class aliases only, as the service providers section is right above aliases. Maybe there’s indeed a reason behind that decision. 🤷🏻‍♂️

@taylorotwell
Copy link
Member

I think because aliases are more rarely changed.

@andriihorpenko andriihorpenko deleted the feat/default-service-providers branch April 18, 2022 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants