-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Add ContainerConfigurator::compilerPass()
to allow specifying compiler passes
#40355
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
…low specifying compiler passes
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
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.
Thank you for your PR. Can you please add tests for your change?
@derrabus I would gladly do so but haven't found any tests related to the |
The more I read the original issue, the more I think that bundles are the appropriate way to create modules. In the linked issue, you state that you want defaults: this is done by instantiating a PhpFileLoader in a bundle's extension load() method (see FrameworkExtension for an example). You also write that "the bundle approach would not work for projects that use the DI component as a standalone library outside of Symfony.", but you examples all use the HttpKernel component, which is the one that provides the bundle system. It can be used standalone. I made this proposal to add this method but having taken time to look closer at the code, I think that ContainerConfigurator should keep its focus on being another format to define DI config, and that it should be very close to what yaml/xml/etc formats provide. For modules, I don't see why bundles wouldn't be a fit, even in your case. |
@nicolas-grekas Doing the same in the bundle system requires quite a lot of boilerplate code which gives a tedious DX. In essence:
All these steps are only for wiring things up so one can end up configuring the container. It also means that part of the work of a bundle on the container is inside the My experience might be very limited compared to yours, but usually my use of compiler passes and the way the services are defined often change together, so it makes sense to have them close. The bundle system makes a lot of sense for reusable code across multiple projects by forcing a standard approach that is easy to comprehend, but not so much for code that is specific to a single project. The reason I wanted to go with a custom "Module" system instead of bundles was that it is quite a lot of work What I had come up with was the following (once I had type hinted the kernel to use the
This ends up being a lot simpler and keeps all things container-related grouped together in a single bootstrapping class.
I fail to see how this would break this contract of being very close to the other formats. The container is for specifying dependencies in a unified way, yet, some of its dependencies have to be set up differently (compiler passes) and in another location. Aren't compiler passes still a form of configuration of the container? |
#40600 will allow getting the container by type-hinting it, wouldn't this solve your usecase? |
When using the PHP-DSL, the ContainerBuilder is passed as a 2nd argument to the configuration closure:
Doesn't that solve your use case? |
@nicolas-grekas Is is it available directly from the Kernel? In my case, I am loading configuration classes from there rather than using closures. |
ContainerConfigurator::compilerPass()
to allow specifying compiler passes
friendly ping @nicolas-grekas , thanks |
I don't think so from the kernel: That being said, I had a look at https://github.com/Morebec/orkestra-symfony-bundle/ and I think there might be something to improve in the design there: a bundle should not ship a kernel. I get that's the way you managed to hook your module system, but I'd suggest looking for another approach instead. I can think of two and can't really decide which one would work or fit in the end:
An alternative that requires less changes on your side might be to call I'm going to close here because I'm not convinced that the described use case fits the purpose of |
For the record, I'm proposing to add a 3rd |
As discussed in #35554 this PR adds
ContainerConfigurator::compilerPass()
in order to allow to add compiler passes to the container using theContainerConfigurator
.