-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] ContainerConfigurator vs ContainerBuilder - how to load services of a namespace, and have access to adding compiler passes. #35554
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
You need a bundle apparently, that's exactly what they are for. |
@nicolas-grekas Hi Nicolas, thank you for answering. Also, the bundle approach would not work for projects that use the DI component as a standalone library outside of Symfony. I partially managed to do it this way: protected function loadNamespace(ContainerBuilder $container, Definition $templateDefinition, string $namespace, string $namespacePath): void {
$loader = new PhpFileLoader($container, New FileLocator($namespacePath));
$loader->registerClasses($templateDefinition, $namespace, $namespacePath . '/**');
} my que But it does not load subnamespaces, only the top level one. EDIT: For the code snippet above I got it to work, removing the |
@jwillp You might like local packages approach we use on our Czech PHP community website. There is ~15 local packages with own config and namespace: https://github.com/pehapkari/pehapkari.cz/tree/master/packages This is how Kernel loads them: https://github.com/pehapkari/pehapkari.cz/blob/bf29677bf20c022ae6a458aecd2921bf3dcb20f5/src/PehapkariKernel.php#L47-L57 Resources |
Thank you for this issue. |
Friendly reminder that this issue exists. If I don't hear anything I'll close this. |
Reading this again, maybe we could add |
Hi @nicolas-grekas, Yes that would be nice solution! |
Thank you for this issue. |
Description
I am facing an issue that I can't seem to resolve nicely.
The code I am working on uses a series of "modules".
Each module has a ModuleConfigurator class that is responsible for configuring the module and its dependencies.
The way these dependencies are configured might depend on complex logic, which is better handled by using PHP.
The way they are loaded looks as follows:
The issues I am facing are:
The container builder does not provide something like this. Also, it does not provide a way to specify defaults. Meaning I would be better off using a ContainerConfigurator. Fine with me, but as per the documentation the only way is by using a PhpFileLoader that needs a script that returns a function, but I already have a class for this. So, I guess a workaround would be by providing a callback to my static method? But this leads me to my second issue:
The ContainerConfigurator does not provide a way to add a Compiler Pass to the underlying container. It does not give access to the container builder at all.
I could wire things up so I can pass both the ContainerConfigurator and the ContainerBuilder, but that seems a little repetitive given the ContainerConfigurator has access to the container.
Suggestion
I have seen that in the latest version on master 5.1.0 not released yet, the KernelTraits now allows to type hint the
configureContainer
method with either aContainerBuilder
or aContainerConfigurator
. Which is pretty nice by the way, but would mean from what I understand so far, that:What I could see, would be to expose the ContainerBuilder using a getContainerBuilder method on the ContainerConfigurator.
Maybe, I am completely off track, but I haven't seen anything in the documentation, that would address my use case.
The text was updated successfully, but these errors were encountered: