I found the following undocumented feature in the documentation chapter Miscellaneous Configuration:
A resource file can be one of many types. PHP, XML, YAML, INI, and closure resources are all supported by the imports directive.
The class in charge of loading these resources seems to be:
Symfony\Component\DependencyInjection\Loader\ClosureLoader ( APIdoc , Code )
In my understanding according to the documentation it should be possible to import services and/or parameters using a PHP closure inside a configuration file.
non-working example:
# app/config/config.yml
imports:
# closure? something like eval( <multiline-string> ) ?
- { resource: >
function($containerBuilder) {
return array(
'parameters' => array(
'upload_tmp_dir' => ini_get('upload_tmp_dir')
)
);
}
}
I can't find an example showing how to use this loader in a PHP,XML,YAML configuration file with the imports directive.
Is there any example available using
imports
?Is the
ClosureLoader
compatible with theYAML
format?
There is an example available that shows how to use the Symfony\Component\Routing\Loader\ClosureLoader
to load a route collection ( Routes as Closures).
But it does not show how to use the closure with the imports
directive as the documentation states.
The idea behind my question is that it might be possible to access PHP's configuration values or some class constants in config.yml
without creating an extension/compiler-pass or importing a file in a different configuration format. ( i.e. accessing constants is not possible in YAML format ).
This would open up some great possibilities ...
... like adding a closure that imports a parameter for the upload_tmp_dir
path in php.ini
that can instantly be used in LiipMonitorBundle's liip_monitor.checks.writable_directory
array afterwards.