[11.x] Simple scoped bindings container registration #52481
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In #37521, Laravel introduced "scoped" binding. This PR adds support for a
$scopedBindings
property on service providers to allow for the registration of simple scoped bindings. It also has support for tersely binding classes that don't have a backing contract, as was introduced for simple singleton bindings in #43469.For "regular" bindings and singletons, there already exist convenient properties (
$bindings
and$singletons
respectively), that can be used to simplify registration of bindings.When using Laravel Octane, you regularly encounter situations where you might want to use a scoped binding, but currently you need to implement the
register()
method when you want to do this.Before:
When skimming the code above, it feels like there is a fundamental difference between the different types of bindings.
When looking at the code below, the connection between the three types of bindings is more obvious.
After: