Closed odolbeau closed 4 years ago
I don't know if Symfony suggest something for bundles?
That is a good question.
There is an issue with autoconfigure, what if I (as an application author) have my custom kernel and chose not to include all the "standard" compiler passes. Then autoconfigure will not work as we (as library authors) intended.
Sure, this is a rare scenario, but the fix is super simple from the bundle's side. I think we can write the proper DI tags ourself.
I dont see the same downside with autowire,
@Nyholm interesting scenario.
Instead of compiler passes for registering tags I'd suggest using _instanceof:
in combination with autoconfigure:true
so userland can not disable them.
_instanceof:
TranslatorInterface:
tags: 'translation.translator'
In my opinion, bundles should not rely on the assumption that the user has autowire enabled.
Did some extra investigation to provide a full picture on the issue:
It's the Bundle
class that (via the compiler pass) imports the yaml
service configuration. The autowiring defaults apply to the yaml file.
So to my best knowledge, disabling autowire / autoconfigure in userland's service.yaml
does not affect any other service import.
Did check the ContainerBuilder
signatures, and did not find a way to get / override the compiler passes (there are no "remove" or "get" methods). Would there be any way to override a pass (except for not adding TranslationBundle
in bundles.php
at all)?
I took a look at the Symfony documentation and here is what I found: https://symfony.com/doc/current/bundles/best_practices.html#services
Services should not use autowiring or autoconfiguration. Instead, all services should be defined explicitly.
Furthermore, it looks like it wasn't a good idea to use FQCN... :/
If the bundle defines services, they must be prefixed with the bundle alias instead of using fully qualified class names [...]
Great find, because that gives us our answer 👍 Feel free to close this issue, unless we want to document following these best practices somewhere.
Did check the ContainerBuilder signatures, and did not find a way to get / override the compiler passes (there are no "remove" or "get" methods). Would there be any way to override a pass (except for not adding TranslationBundle in bundles.php at all)?
You can just not add compiler passes.
So autowire/autoconfigred cannot be "disabled". But a user can configure how "autoconfigure" is working. And there is no way a bundle can detect it.
I agree with @XWB and the best practices. I'll close this issue.
Furthermore, it looks like it wasn't a good idea to use FQCN
For services that we intend the user to use, they should use FQCN. For internal services for our bundle only, they should not use FQCN.
But, I really dont mind if all services have FQCN. =)
What about moving all
autowire
&autoconfigure
to a_defaults
section?Originally posted by @rvanlaak in https://github.com/php-translation/symfony-bundle/pull/370