引用 config.yml 中的非参数条目

Referencing non-parameter entries in config.yml

我有相当多的配置 .yml 文件,我想参考那里的各种设置:

security:
    role_hierarchy:
        ROLE_ADMIN: ROLE_USER
        ROLE_SUPER_USER: ROLE_ADMIN

easy_admin:
    entities:
        Group:
            form:
                fields:
                    - 
                      property: 'roles' 
                      type: choice
                      type_options: 
                          expanded: true
                          multiple: true
                          choices: "%security.role_hierarchy%"

最后一行当然不行,因为%security.role_hierarchy%指的是parameters.security.role_hierarchy。在 easy_admin 部分是否有任何有效的方法来引用 security.role_hierarchy

在 YAML 中唯一有效的方法是使用标准功能 anchors and aliases。锚点(将要引用的内容)由 &<name> 表示,别名(引用锚点的一个或多个点)由 '*`:

表示
security:
    role_hierarchy: &hr1
        ROLE_ADMIN: ROLE_USER
        ROLE_SUPER_USER: ROLE_ADMIN

easy_admin:
    entities:
        Group:
            form:
                fields:
                    -
                      property: 'roles'
                      type: choice
                      type_options:
                          expanded: true
                          multiple: true
                          choices: *hr1

映射条目 choices 的值,检索时将是映射:

ROLE_ADMIN: ROLE_USER
ROLE_SUPER_USER: ROLE_ADMIN

(转换为编写 YAML 解析器的编程语言的散列或类似字典的对象),并且与键 role_hierarchy.

的值是相同的实体