Reputation: 96891
I have a bundle with its custom *Extension
class where I need to read configuration from another bundle (SecurityBundle in particular) where I have for example.
security:
...
firewalls:
main:
pattern: '^%url_prefix%'
I'm wondering how can I get value for security.firewalls.main.pattern
with interpolated url_prefix
parameter?
Upvotes: 1
Views: 498
Reputation: 13167
Retrieving configuration values (of any bundle different than the one into what your extension is located, because you are in an extension) is not supported, and it seems that'll not be in the future.
The only ways are:
Define a parameter representing the whole option's value (as pointed by this answer on a similar question):
# app/config/security.yml
parameters:
firewalls.main.pattern: '^%url_prefix%'
# ...
security:
# ...
firewalls:
main:
pattern: '^%url_prefix%'
Parse your config.yml
using the Yaml component:
$yamlPath = $this->getParameter('kernel.root_dir').'/config/security.yml';
$config = Symfony\Component\Yaml\Yaml::parse(file_get_contents($yamlPath));
// The option value
$value = $config['security']['firewalls']['main']['pattern'];
I think that's really a pity to don't be able to retrieve a config option from any container-aware context without doing such hacks.
Upvotes: 1