yml中的非参数条目

yml中的非参数条目

本文介绍了引用config.yml中的非参数条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have quite extensive config .yml files and I'd like to refer to various settings there:

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

Of course the last line doesn't work because %security.role_hierarchy% refers to parameters.security.role_hierarchy. Is there any valid way to reference security.role_hierarchy in easy_admin section?

推荐答案

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

The only valid way to do that in YAML is using the standard feature anchors and aliases. Anchors (that what is going to be referenced) are indicated by &<name> and alias (one or more points where the anchor is referenced) are indicated by '*`:

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

映射条目选择的值,当检索到时将是映射:

The value for the mapping entry choices, when retrieved will be the mapping:

ROLE_ADMIN: ROLE_USER
ROLE_SUPER_USER: ROLE_ADMIN

(翻译为哈希或字典YAML解析器所写的编程语言的类似离子对象,并且与键 role_hierarchy 的值是同一实体。

(translated to the hash or dictionary like object of the programming language the YAML parser is written in), and is the same entity as the value for the key role_hierarchy.

这篇关于引用config.yml中的非参数条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 00:53