[8.x] Add before resolving callbacks #35228
Merged
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.
Description
As mentioned in #35202, this PR enables us to hook some custom logic into the beginning of the container resolution — i.e. before an instance as been resolved from the provided abstract.
Usage
It uses the same conventions as the
$(after)ResolvingCallbacks
and$global(After)ResolvingCallbacks
to register and trigger the callbacks.Advanced usage
These before resolving callbacks can be used as a way to dynamically add specific extenders and, therefore, remove the need for #35202.
For example, this global extender...
... could be achieve with the following before resolving callback:
Since the specific before resolving callbacks already check for inheritance, this could be refactored to:
Note the use of
$app->resolved($abstract)
, to ensure we do not add the same extender multiple times.Backward compatibility
This PR does not add any breaking changes.
It triggers new types of callbacks that wouldn't have been registered before.