-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
Fix return type to generic in ReflectionBasedAbstractFactory #222
base: 3.23.x
Are you sure you want to change the base?
Conversation
4df788b
to
6dc43ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but the baseline got reduced by too much 🤔
6dc43ce
to
31c551a
Compare
Signed-off-by: Witold Wasiczko <[email protected]> Signed-off-by: Witold Wasiczko <[email protected]> Fix
31c551a
to
2592e40
Compare
Same generic can be applied to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me. Its only sugar for this repository only so feel free to add the same logic to the other factories as well, no need to have dedicated PRs for this.
I also don't think that we are fixing anything here. We just adjust the type inference which actually does not fix anything but provides more precise type inference which is only needed in this repository (i.e. in tests, etc.). In actual applications, these factories are never called from code inside of these projects, its all within ServiceManager#doCreate
and thus nothing upstream users will benefit from. I don't say that this is useless, it helps us reducing our baseline, but thats it.
So I'd rephrase the PRs title to something like "Adjusting type inference for pre-defined factories", but up to you.
I have a case where I use $container->get(ReflectionBasedAbstractFactory::class)($container, MyClass::class); |
Why not registering return [
'factories' => [
MyClass::class => ReflectionBasedAbstractFactory::class,
],
]; That would also enable v4 to actually AoT generate a real factory. With your example, thats not possible. So yes, your code works, but that will always use reflection at runtime to determine what services need to be injected into |
I have already registered this service (and share it in multiple places), but I need - in some case - new instance. I can create new factory and pass by hand, I know, but now for me development time is more important than performance. |
The |
Yeah, I would also use Only problem with the |
I forgot about |
Description
ReflectionBasedAbstractFactory
has invalid return type when invoking. This PR adds also generics to return type, because it always create class directly from$requestedName