Skip to content

Conversation

@ollieread
Copy link
Contributor

@ollieread ollieread commented Oct 31, 2024

This PR adds the Application::removeDeferredServices() method. The Application class already has a series of methods for interacting with deferred services:

  • getDeferredServices() - Get all deferred services
  • setDeferredServices(array $services) - Overwrite all deferred services
  • addDeferredServices(array $services) - Merge an array of services into the current deferred services
  • isDeferredService(string $service) - Determine if a service is deferred

Currently, if you wanted to remove a service from the deferred service list, you'd have to do something like so:

$deferredServices = $app->getDeferredServices();

unset($deferredServices['auth.password'], $deferredServices['auth.password.broker']);

$app->setDeferredServices($deferredServices);

This is real code I currently have in a package. This PR adds what I consider to be a missing method, which replaces the above code with the following:

$app->removeDeferredServices(['auth.password', 'auth.password.broker']);

I appreciate that this is an obscure use case, but I figured it's worth a PR for such a simpler method with very little overhead and a tiny footprint.

From my use case, I'm providing a custom binding for auth.password and auth.password.broker, which I'm aware will be hit before those deferred services are overridden. This is simply a way to tidy up, and prevent rare edge cases where they end up being loaded after I've overridden.

@taylorotwell taylorotwell merged commit 16bf809 into laravel:11.x Oct 31, 2024
5 checks passed
@ollieread ollieread deleted the feat/remove-deferred-services branch October 31, 2024 20:06
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.

2 participants