silverstripe-framework: InjectionCreator::create() use of ReflectionClass throws an unhelpful error
Affected Version
silverstripe/framework 4.1.0
Description
Uncaught SilverStripe\Core\Injector\InjectorNotFoundException: ReflectionException: Class AML\Tests\Action\DummyAMLAction does not exist in /var/www/public/vendor/silverstripe/framework/src/Core/Injector/InjectionCreator.php:17
isn’t a useful error when you have the class on file with a namespace
that exactly matches the FQDN in the error, and can’t determine why ReflectionClass
doesn’t see it
NOTE
This issue is specifically about the fact that the error message doesn’t provide an indication of why the class may not have been found (e.g. autloloading hasn’t happened yet) - there are suggestions in this thread for how to handle that.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 16 (16 by maintainers)
The logic used has change now - reflection isn’t used at all. I’m going to close this with the assumption that it is no longer a problem, but feel free to reopen if that assumption is false.
Thanks for pointing that out @NightJar. I’ve reopened this, though this is a low priority so I suspect it won’t be dealt with unless a community member takes it upon themselves to create a PR.
Hi guys, I also came up against this error which in my case occurred when defining the routes. Anyway it might be useful to someone out there, I added the nanamespace to the controller name and this worked for me! 😉
Sure, well what I’ll do is change this to a docs issue (rather than a bug). This will only be useful if someone is willing to write up the draft docs though. 😛
Thanks @NightJar, that’s exactly right.
@tractorcow I appreciate you taking the extra time to elaborate. The added insight is really valuable.
@dhensby Ideally it would be an error that infers a viable recourse.
This could be fulfilled with an error like
Class AML\Tests\Action\DummyAMLAction is not available to the InjectionCreator. Classes must meet Silverstripe's class loading conditions.
Complement that with a doc on “Class loading conditions”, which describes all of the inclusive and exclusive patterns, so that a user can have a clear understanding of when they should expect their class to be loaded.
Side note: It seems a little backward to follow the below guideline for a PR, when an issue is closed.
But based on what @tractorcow is saying it sounds like there may be a practice of raising PR’s against closed issues?
I think this was a valuable discussion, but I feel it’s gone off topic, so I’m happy for this to remain closed to avoid any further discourse.