Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[DependencyInjection] AddContainerConfigurator::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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…low specifying compiler passes
carsonbot commentedMar 3, 2021
Hey! I see that this is your first PR. That is great! Welcome! Symfony has acontribution 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 |
derrabus left a comment
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?
jwillp commentedMar 3, 2021
@derrabus I would gladly do so but haven't found any tests related to the |
nicolas-grekas commentedMar 10, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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. |
jwillp commentedMar 10, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@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? |
nicolas-grekas commentedApr 11, 2021
#40600 will allow getting the container by type-hinting it, wouldn't this solve your usecase? |
nicolas-grekas commentedApr 12, 2021
When using the PHP-DSL, the ContainerBuilder is passed as a 2nd argument to the configuration closure:
Doesn't that solve your use case? |
jwillp commentedJun 29, 2021
@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 passesOskarStark commentedAug 1, 2021
friendly ping@nicolas-grekas , thanks |
nicolas-grekas commentedSep 8, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I don't think so from the kernel: That being said, I had a look athttps://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 |
nicolas-grekas commentedSep 13, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
For the record, I'm proposing to add a 3rd |
Uh oh!
There was an error while loading.Please reload this page.
As discussed in#35554 this PR adds
ContainerConfigurator::compilerPass()in order to allow to add compiler passes to the container using theContainerConfigurator.