-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Fixing a bug where abstract classes were wired with the prototype loader #22681
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
Conversation
@@ -108,7 +108,7 @@ private function findClasses($namespace, $pattern) | |||
if (!$r = $this->container->getReflectionClass($class)) { | |||
throw new InvalidArgumentException(sprintf('Expected to find class "%s" in file "%s" while importing services from resource "%s", but it was not found! Check the namespace prefix used with the resource.', $class, $path, $pattern)); | |||
} | |||
if (!$r->isInterface() && !$r->isTrait()) { | |||
if (!$r->isInterface() && !$r->isTrait() && !$r->isAbstract()) { |
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.
$r->isInstantiable?
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.
Nice idea 👍
cd38948
to
ae3ebc2
Compare
@@ -108,7 +108,8 @@ private function findClasses($namespace, $pattern) | |||
if (!$r = $this->container->getReflectionClass($class)) { | |||
throw new InvalidArgumentException(sprintf('Expected to find class "%s" in file "%s" while importing services from resource "%s", but it was not found! Check the namespace prefix used with the resource.', $class, $path, $pattern)); | |||
} | |||
if (!$r->isInterface() && !$r->isTrait()) { | |||
// skip interfaces, traits, abstract classes & private constructors | |||
if ($r->isInstantiable()) { |
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.
I'm not certain we should skip private constructors, users could define a factory when having some.
ae3ebc2
to
5326bab
Compare
I just changed away from |
Thank you @weaverryan. |
…ototype loader (weaverryan) This PR was merged into the 3.3-dev branch. Discussion ---------- Fixing a bug where abstract classes were wired with the prototype loader | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | n/a The prototype/PSR-4 loader currently tries to wire abstract classes. The problem is if, for example, you have, for example: ```php abstract class BaseCommand extends Command { } ``` If this is registered as a service, and you have `autoconfigure`, then the console `Application` will try to use this a command. Was there some reason abstract classes were originally allowed to be registered as services with the PSR4/prototype loader? I don't know if there is a real use-case for registering abstract classes. If you wanted to use that service as a parent service... then you'll probably be configuring it yourself anyways. We could also fix this by changing all tags compiler passes to skip classes that are abstract... *if* there is a use-case for Abstract classes being auto-registered. Cheers! Commits ------- 5326bab Fixing a bug where abstract classes were wired
The prototype/PSR-4 loader currently tries to wire abstract classes. The problem is if, for example, you have, for example:
If this is registered as a service, and you have
autoconfigure
, then the consoleApplication
will try to use this a command.Was there some reason abstract classes were originally allowed to be registered as services with the PSR4/prototype loader? I don't know if there is a real use-case for registering abstract classes. If you wanted to use that service as a parent service... then you'll probably be configuring it yourself anyways. We could also fix this by changing all tags compiler passes to skip classes that are abstract... if there is a use-case for Abstract classes being auto-registered.
Cheers!