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
Dependency injecting callable objects #1487
Comments
Yes it doesn't instantiate things that have unknown type hinting. I't should be fixed, but it should also be fixed in compiler. Did you try to run compiler? We have integration tests: dev/tests/integration/Magento/Framework/ObjectManager |
@danslo Thanks for raising this issue. It will be great if you can submit a pull request. Unit test for this class can be added under directory: lib/internal/Magento/Framework/Code/Test/Unit/Reader. |
@joanhe @antonkril Yeah my diff was more meant as some insight, not as something expected to be merged. I need to do a bit more research before I feel confident to write some tests, maybe update the compiler, etc. Give me a couple of days ;-) |
Hi @danslo, do you have some updates? |
@ilol I have a module of mine that depends on this functionality but I haven't gotten around to fixing it in Magento2 yet. I definitely do intend to come back to this soon though. |
I will close this for now as I'm currently not finding time to look into this and I worked around this by using wrapper classes that just instantiates |
Ok, thank you, @danslo |
/cc #2026 |
Imagine having a third party library:
Now also imagine we define our own callable object:
This works fine when injecting dependencies manually:
However, this doesn't work when we use the Magento2 DI system:
Instead of an instance of
CallableClass
, Magento 2 will attempt to inject an array:which obviously results in something bad:
I never gave you an array, I gave you an object!
I managed to fix this by checking for
ReflectionParameter::isCallable
inMagento\Framework\Code\Reader::getConstructor
:I am however having difficulties finding the appropriate place to create tests for this. Adding a unit test for this method will be easy, but the DI mechanism itself must be tested as well.
I also haven't exactly found why that object is being wrapped in an array. I assume this is default behavior for things it doesn't know (like callable)?
Input here would be much appreciated.
The text was updated successfully, but these errors were encountered: