k0pernikus
k0pernikus

Reputation: 66460

How to fix ParameterCircularReferenceException?

I have a symfony2 appliciation. We have previously set up a docker-compose stack for development, and this is why we want all its configuration to bet set via environment variables instead of the parameters.yml.

Hence I replaced the content of my parameters.yml from:

parameters:
    locale: 'en'
    secret: 'SOME_SECURITY_TOKEN'
    ...

to:

parameters:
    locale: '%locale%'
    secret: '%secret%'
    ...

My docker-compose.yml file contains:

my_app:
    hostname: my-app
    build: .
    dockerfile: Dockerfile.dev
    ports:
        - "9080:80"
        - "9043:433"
    environment:
        LOCALE: en
        SECRET: SOME_SECURITY_TOKEN
        ...

Yet after rebuilding my container I get the exception:

ParameterCircularReferenceException in ParameterBag.php line 209: Circular reference detected for parameter "secret" ("secret" > "secret").
    1. in ParameterBag.php line 209
    2. at ParameterBag->resolveString('%secret%', array('secret' => true)) in ParameterBag.php line 185
    3. at ParameterBag->resolveValue('%secret%', array('secret' => true)) in ParameterBag.php line 214
    4. at ParameterBag->resolveString('%secret%', array('secret' => true)) in ParameterBag.php line 185
    5. at ParameterBag->resolveValue('%secret%', array()) in ParameterBag.php line 175
    6. at ParameterBag->resolveValue(array('secret' => '%secret%', 'router' => array('resource' => '%kernel.root_dir%/config/routing.yml', 'strict_requirements' => null), 'form' => null, 'csrf_protection' =>
       null, 'validation' => array('enable_annotations' => true), 'templating' => array('engines' => array('twig')), 'default_locale' => '%locale%', 'trusted_hosts' => null, 'trusted_proxies' => null,
       'session' => array('handler_id' => 'api.session.handler.memcached'), 'fragments' => null, 'http_method_override' => true), array()) in ParameterBag.php line 175
    7. at ParameterBag->resolveValue(array(array('secret' => '%secret%', 'router' => array('resource' => '%kernel.root_dir%/config/routing.yml', 'strict_requirements' => null), 'form' => null,
       'csrf_protection' => null, 'validation' => array('enable_annotations' => true), 'templating' => array('engines' => array('twig')), 'default_locale' => '%locale%', 'trusted_hosts' => null,
       'trusted_proxies' => null, 'session' => array('handler_id' => 'api.session.handler.memcached'), 'fragments' => null, 'http_method_override' => true), array('router' =>
       array('resource' => '%kernel.root_dir%/config/routing_dev.yml', 'strict_requirements' => true), 'profiler' => array('only_exceptions' => false)))) in MergeExtensionConfigurationPass.php line 45
    8. at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in MergeExtensionConfigurationPass.php line 39
    9. at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in Compiler.php line 107
   10. at Compiler->compile(object(ContainerBuilder)) in ContainerBuilder.php line 589
   11. at ContainerBuilder->compile() in bootstrap.php.cache line 2687
   12. at Kernel->initializeContainer() in bootstrap.php.cache line 2465
   13. at Kernel->boot() in bootstrap.php.cache line 2496
   14. at Kernel->handle(object(Request)) in app_dev.php line 30

Yet in my container I do see the env variables:

le-container:/var/www/my-app# env
SECRET=SOME_SECURITY_TOKEN
LOCALE=en

What am I doing wrong and how to fix it?

Upvotes: 0

Views: 711

Answers (3)

Katch
Katch

Reputation: 180

There is a solution to use external parameters. Prefix your variables with "SYMFONY__". In your case it would be:

my_app:
    ...
    environment:
         SYMFONY__APP__LOCALE: en
         SYMFONY__APP__SECRET: SOME_SECURITY_TOKEN
    ...

And in your parameters you can call it as followed:

parameters:
    locale: %app.locale%
    secret: %app.secret%

Upvotes: 0

Arthur
Arthur

Reputation: 2889

parameters:
    locale: '%locale%'
    secret: '%secret%'

Is useless construction, locale and secret already is parameters. Just remove this block.

Upvotes: 0

k0pernikus
k0pernikus

Reputation: 66460

For some reason, adding a prefix to my environment variable fixed the issue:

parameters:
    locale: '%foo_locale%'
    secret: '%foo_secret%'

and of course whenever the variable is set as well. My current working theory is that symfony doesn't like having the same parameter name and env variable, yet I am not sure.

Upvotes: 1

Related Questions