Contributed by
Pierre du Plessis
in #21270.
Symfony DependencyInjection组件 极为灵活,你可以导入其他文件到你程序的配置文件中。比如在需要时,你可以混合不同的配置格式:
1 2 3 4 5 6 7 | # app/config/config.yml
imports:
- { resource: '../common/config.yml' }
- { resource: 'dynamic-config.php' }
- { resource: 'parameters.ini' }
- { resource: 'security.xml' }
# ... |
你也可以导入整个目录来加载那里面的全部资源:
1 2 3 4 5 | # app/config/config.yml
imports:
- { resource: '../common/' }
- { resource: 'acme/' }
# ... |
在Symfony 3.3我们改进了此项功能,以支持 使用glob patterns来导入配置文件。这将简化你的配置文件,因为现在你能以一种小型化的方式来导入许多种不同格式的资源:
1 2 3 4 5 6 7 | # app/config/config.yml
imports:
- { resource: "*.yml" }
- { resource: "common/**/*.xml" }
- { resource: "/etc/myapp/*.{yml,xml}" }
- { resource: "bundles/*/{xml,yaml}/services.{yml,xml}" }
# ... |