[5.4] Add support for binding methods to the container #16800
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.
Adds support for manually controlling how a method should be called when invoked with Container::call:
Prior to this, it was impossible to have parameters in the
handle
method of a job that could not be auto-resolved by the container, because there was no way to manually control what the parameters should be.This means you are forced to use type hints for object parameters and have no ability to use primitives as parameters, or have to use the old undocumented job syntax where dependencies were passed to the constructor instead of to the
handle
method.For example, it is currently impossible to write a job class like this, where the
handle
method has dependencies that can't be autoresolved:Using the functionality added in this PR, you could specify how handle should be called:
This PR intentionally adds only the minimal functionality needed to subvert this issue, and doesn't make any effort to support the
when->needs->give
syntax, or passing key => value parameters to optionally override things or any of those fancy more complex features.Instead, it simply adds support for defining what should happen as a whole, much like you would with a standard container binding:
Additional functionality like that could be added down the road, or we could simply roll with this forever, because it at least does what's needed to fix what's currently impossible.