-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.6] Improve allowed method injection parameters #24234
[5.6] Improve allowed method injection parameters #24234
Conversation
Pretty sweet, and exactly what I need for some stuff I'm working on 😄 |
Seems pretty nice to me. 👍 |
|
Yeah that's correct. I'm not sure if we need to handle this logic. Until now, it wasn't possible to override specific hinted classes with method injection, so the case that someone needs to override two specific instances of the same class in combination with method injection could be quite rare.
Do we need to handle this extreme edge case? The same edge case occurs right now when using the |
If you already know the function needs that instance... couldn't you have done... function () use ($stub) {} |
Ping @mpociot |
@taylorotwell I don't quite understand what you mean. Could you explain it some more? I want to be able to inject a specific object instance using method injection, but I have no idea what's the name of the parameter - I only know the type-hinted class. For example, if you're developing a package that needs to inject a specific instance into a method, the only way to do it right now, is to tell people how they need to name the method properties. Then we could pass an array of parameters with this exact parameter name. With this PR, we would be able to say: Just typehint this class and it will be injected automatically and pass the parameters with the fully qualified class name - just like I did in the added test. |
@mpociot Would it make sense to implement that as a parent/child container? Where a child container would forward unknown resolve attempts to the parent container. This would also solve scenarios where a dependency of a dependency of a dependency were to resolve the contract, instead of just the method you're calling.
|
@taylorotwell ,should be documentation update? If yes, @mpociot could you update the documentation? |
This PR adds the ability to pass a specific object instance to a method called from the container, regardless of the parameter name.
This can be useful in situations where you want to inject a specific object instance into a method call, no matter what name that parameter has.