2016-03-08 109 views
0

我有一個symfony2應用程序。我們之前已經爲開發建立了一個docker-compose棧,這就是爲什麼我們希望它的所有配置都是通過環境變量而不是parameters.yml進行設置的。如何修復ParameterCircularReferenceException?

因此,我取代了我parameters.yml的內容來源:

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

到:

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

docker-compose.yml文件包含:

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

然而,重建我的容器後,我獲得例外:

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 

然而,在我的容器我也看到了ENV變量:

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

什麼我做錯了,如何解決呢?

回答

1

出於某種原因,添加前綴到我的環境變量固定的問題:

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

當然每當變量設置爲好和。我目前的工作理論是,symfony不喜歡具有相同的參數名稱和env變量,但我不確定。

+1

你的描述是什麼;-)的parameterbag級解析「參數值譜寫」並在它們的parameters.yml中查找,所以這是無止境的 –

+0

@johnSmith看起來你已經在symfony2源代碼中找到了負責任的部分。你能否添加一個鏈接到相關部分?我想我會在他們的github上公開一個關於它的問題。 – k0pernikus

+0

我認爲你誤解了,你的實際問題是參數名稱是相等的,所以類解析引用並再次在parameters.yml中找到引用,等等,但它是一個內置功能使用外部參數;-) –

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

是無用的建設,現場和祕密已經是參數。只要刪除這個塊。

+0

我通過環境變量注入值。 – k0pernikus

0

有一個解決方案使用external parameters。用「SYMFONY__」前綴你的變量。在你的情況將是:

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

而在你的參數,你可以把它叫做如下:

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