-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Anonymous services do not work for global classes #22146
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
Comments
True, and not a bug: only namespaced classes can have their class attribute omitted, as before 3.3. Twig_Extensions_Extension_Intl:
class: Twig_Extensions_Extension_Intl |
Note that this looks like an argument to add namespaces to Twig :) |
I would've expected this exception in the blog post on the subject ;) Just curious though - the restriction seems arbitrary to me, why would this be forbidden? The absence of the |
@curry684 this is because service ids are not required to be class names. When we see a @javiereguiluz can you update the blog post to add a note about the shortcut syntax requiring to use namespaces ? |
@stof I fully agree such an error would be confusing, but there's no need to? If the class property is missing and the ID is not a loadable class we could throw a verbose mess
8000
age during compilation stating that a service definition either has to be named after a defined class, or contain a Not like the current situation is all that good since I can still define services with a backslash in the name (unconventional but not forbidden) and point them to completely different classes. |
See also #21380 |
@curry684 would you like to submit a PR to enhance the exception message (adding a class_exists + interface_exists check to make it more DX friendly?) |
I'll try to make some time for this and #22143 this weekend or early next week. Just to be clear: I would be allowing the use case in the opening post, by first checking for class property, then backslashes, then the class/interface check. And if all fail throw a proper and verbose error during compilation describing the problem. |
The service definitions should remain context free, which means we should not do a class_exists check to turn Instead, we should just make sure the exception message thrown by |
Ok I can agree with that for now as it is the most consistent solution, I see the context argument, and fixes the DX. As a whole my morning spent using all the new service features in 3.3-dev in a big 3.2 project did give me a bunch of icky feelings about the recent movement of the DI container, and I do think a lot of this recent stuff has to be rethought as a whole for 4.0 next year. I think the features are generally great but the cohesion within the current BC constraints is 'suboptimal'. Just looking at this issue I see that service IDs starting with a There's some DX to be done in DI imho :) |
…asses As discussed in symfony#22146 the error message received when trying to use a class in the global namespace as a service without defined class is confusing. Helpful information was added pointing out this current limitation.
We have two months of feat freeze to make things as best as possible. Your PR #22153 is on this path :) |
Happy to help, that's why I share my real world experiences :) |
…asses As discussed in symfony#22146 the error message received when trying to use a class in the global namespace as a service without defined class is confusing. Helpful information was added pointing out this current limitation.
…asses As discussed in symfony#22146 the error message received when trying to use a class in the global namespace as a service without defined class is confusing. Helpful information was added pointing out this current limitation.
…bal classes (curry684) This PR was merged into the 3.3-dev branch. Discussion ---------- [DX] [DI] Throw more helpful error when shortcutting global classes | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? |no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22146 | License | MIT As discussed in #22146 the error message received when trying to use a class in the global namespace as a service without defined class is confusing. Helpful information was added pointing out this current limitation. Commits ------- b9e7b4f [DependencyInjection] Throw helpful error when shortcutting global classes
Using the standard Twig Extensions library, the following definitions work as expected:
While the following doesn't:
It throws:
It seems to be related to the fact that it's a class in the global namespace.
The text was updated successfully, but these errors were encountered: