1

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?

martin
  • 93,354
  • 25
  • 191
  • 226

1 Answers1

1

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.

Community
  • 1
  • 1
chalasr
  • 12,971
  • 4
  • 40
  • 82
  • I written a bundle for that. https://github.com/chalasr/RCHConfigAccessBundle , allowing to retrieve any config value using dot syntax, here it would be: `$pattern = container->get('rch_config_access.accessor')->get('security.firewalls.main.pattern');` – chalasr Sep 29 '16 at 12:16