我无法找到一种方法来包含不同的security.yml
文件,这些文件将根据Symfony2的环境而包含。例如,我想为我的验收测试提供一个内存中的用户提供程序,因为我真的不需要在这里测试我的实体和东西,我只想对我的视图进行验收测试。
但是,事实证明,这不是一件容易的事情。我从config.yml
的包含中删除了security.yml
,将其重命名为security_prod.yml
并创建了一个具有in_memory
用户提供程序的security_test.yml
。然后,我分别在生产和测试配置中包含security_prod.yml
和security_test.yml
。
然而,它似乎根本不起作用:
$ 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.
在我看来,security.yml
文件名是硬编码的(这对Symfony来说太奇怪了),但事实并非如此。
所以问题是:我如何使用Symfony获得多个security.yml
?是什么导致了这种行为?
给那些正在寻找它的人的说明(不要红色评论):
- 为不同的环境创建不同的
config
文件:config_test.yml
、config_dev.yml
、config_prod.yml
- 创建不同的
security
文件:security_test.yml
、security_dev.yml
、security_prod.yml
-
导入
security_test.yml
config_test.yml
等其他环境。config_test.yml
示例:imports: - { resource: security_test.yml }
- 确保你只包含
security_*.yml
一次(基本上作者犯了这个错误)