-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI][RFC] Container scripts #22365
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
Note that the Container needs to be able to work without compiling down to a PHP file first, and eval is only limitedly possible. And adding to much extensions for the dumping process could lead to some hart debug situations and BC promises (as some will expect access to service variables You can already solve the configuration of a service after creation using a Configurator. Allowing to register CompilerPasses (classes only) in services.{xml,yml} file would be a good enhancement. But the PHP version of services.php files already support this (as it receives the ContainerBuilder) so I'm not if its use-case is good enough to support this in other formats as well 🤔 |
what about load time scripts and/or factory scripts? a use case came up exactly with annotation loader PR container build code pushed down into config files could solve the problem (maybe its just my problem) of scattered container build resources but using php as config file format is actually a good idea. some tools of the node.js environment use config files written in js, which has some beauty to it. but this still doesnt solve scripts ran during container "execution" |
-1 for putting code in the config files to be evaled (because this is what you are asking). If you want to have some code running at the instantiation time (your For your build-time logic, use extensions or compiler passes instead of trying to hide things inside services and asking us to eval it. |
You can use a http://symfony.com/doc/current/service_container/configurators.html but it does mean your configuration is separate.
Indeed. |
didnt know about configurators before -- yes they solve the "factory-script" case it still feels cumbersome to search in many different places (and often in 300+ LoC Extension classes) to find the piece of code responsible to build/configure a specific service/group of services. |
Closing as explained. |
In #21837 there was basically a hack used to add some load time code to the container.
Besides that the service configuration defined in the different config files is heavily altered by extensions/configurators/compiler passes so you need to consult a different sources scattered around various places:
Resources/config
,*Bundle.php
(for compiler passes actually used),*Extension.php
(dynamic config),*Pass.php
(for container building code) and some more depending on how sophisticated your feature's DI integration is.The container:debug commands helps only to some degree, to at least get a view of the final result, but still gives no clue about where to look for the configuration of a specific service.
To consolidate these various sources, I propose something like "container-scripts". An example how #21837 could be solved with it:
This would execute the script each time the service "annotations.reader" is initialized/created ("
new
ed").Script scenarios:
<config-script>
script executed during configuration, maybe to include config resources depending on the env; would be executed right after the config resource is loaded (before following config resources are loaded)<build-script>
like extensions<compile-script>
like compiler passes<load-script>
executed when the container is loaded/booted<factory-script>
executed when services are "new
ed"WDYT
The text was updated successfully, but these errors were encountered: