-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[DependencyInjection] Update ResolveClassPass
to check class existence
#61215
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
base: 7.4
Are you sure you want to change the base?
Conversation
src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckServiceClassExistsPassTest.php
Outdated
Show resolved
Hide resolved
740f29a
to
65259c9
Compare
src/Symfony/Component/DependencyInjection/Compiler/CheckServiceClassExistsPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/CheckServiceClassExistsPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/CheckServiceClassExistsPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/CheckServiceClassExistsPass.php
Outdated
Show resolved
Hide resolved
This approach is too broad IMHO. There are cases where the class is eg In #54095 (comment), I wrote:
Can't we patch the existing compiler pass that copies the id to the class when no class is set, and make it throw when id is not a class? |
But then it would not work if you define a manual id and make a typo in the class (although more of a niche case) |
So we could have something like |
65259c9
to
321ccff
Compare
There are many ways one can mess up with their DI config. Validating everything adds to the compilation time. That's something we always considered outside of the scope of the compilation step. |
ResolveClassPass
to check class existence
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, test cases changes look consistent with the updated behavior.
src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/foo.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/foo.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/foo.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/fixture_app_services.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/fixture_app_services.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/fixture_app_services.php
Outdated
Show resolved
Hide resolved
if (!class_exists($id) && !interface_exists($id)) { | ||
$error = $definition instanceof ChildDefinition ? | ||
'has a parent but no class, and its name looks like an FQCN. Either the class is missing or you want to inherit it from the parent service' : | ||
'name looks like an FQCN but the class does not exists'; |
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.
'name looks like an FQCN but the class does not exists'; | |
'name looks like a FQCN but the class does not exist'; |
throw new InvalidArgumentException(\sprintf('Service definition "%s" has a parent but no class, and its name looks like an FQCN. Either the class is missing or you want to inherit it from the parent service. To resolve this ambiguity, please rename this service to a non-FQCN (e.g. using dots), or create the missing class.', $id)); | ||
if (!class_exists($id) && !interface_exists($id)) { | ||
$error = $definition instanceof ChildDefinition ? | ||
'has a parent but no class, and its name looks like an FQCN. Either the class is missing or you want to inherit it from the parent service' : |
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.
'has a parent but no class, and its name looks like an FQCN. Either the class is missing or you want to inherit it from the parent service' : | |
'has a parent but no class, and its name looks like a FQCN. Either the class is missing or you want to inherit it from the parent service' : |
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.
Fixed!
…des/foo.php Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
…des/foo.php Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
9690e1e
to
349c87c
Compare
Currently doesn't check for incorrect factories, but I'm not sure what would be the best approach