针对不同环境的不同security.yml文件

kix*_*kix 10 php symfony

我无法找到一种方法来security.yml包含根据Symfony2环境包含的不同文件.例如,我想为我的验收测试提供一个内存用户提供程序,因为我不需要在这里测试我的实体和内容,我只想对我的视图进行验收测试.

但是,事实证明,这并不容易.我security.yml从我的包中删除config.yml,重命名为security_prod.yml并创建了一个security_test.yml具有in_memory用户提供程序的包.然后,我已经包括了security_prod.ymlsecurity_test.yml我的生产和测试分别CONFIGS.

但它似乎根本不起作用:

$ SYMFONY_ENV=test app/console cache:clear                                                      

  [Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]                                                           
  You are not allowed to define new elements for path "security.providers". Please define all elements for this path in one config file.  

$ SYMFONY_ENV=prod app/console cache:clear                                                      

  [Symfony\Component\Config\Definition\Exception\ForbiddenOverwriteException]                                                                         
  Configuration path "security.access_control" cannot be overwritten. You have to define all options for this path, and any of its sub-paths in one   
  configuration section.                                                                                                                              
Run Code Online (Sandbox Code Playgroud)

在我看来,security.yml文件名是硬编码的(这对于Symfony来说太奇怪了),但事实并非如此.

所以问题是:如何security.yml使用Symfony 获得多个?什么可能导致这种行为?

pli*_*kou 5

给正在寻找它的人的说明(不要红色评论):

  1. 为不同的环境创建不同的config文件:config_test.yml, config_dev.yml,config_prod.yml
  2. 创建不同的security文件:security_test.yml, security_dev.yml,security_prod.yml
  3. 对于其他环境导入 security_test.yml等等。config_test.yml示例config_test.yml

    imports:
      - { resource: security_test.yml }
    
    Run Code Online (Sandbox Code Playgroud)
  4. 确保security_*.yml只包含一次(基本上作者犯了这个错误)