简体   繁体   English

Symfony 2 YAML传递数组

[英]Symfony 2 YAML passing arrays

I wonder where can I get more information about special syntax like @somevar or %somevar% in symfony2's yaml configuration? 我想知道在哪里可以获取有关symfony2的yaml配置中的特殊语法(如@somevar%somevar%更多信息?

For example, using @ defines a call to a service, that is how we pass dependencies to services. 例如,使用@定义对服务的调用,这就是我们将依赖项传递给服务的方式。 %somevar% on the other hand refers to the value of an already defined parameter with the name somevar . 另一方面, %somevar%引用名称为somevar的已定义参数的值。

So, if I do: 所以,如果我这样做:

parameters:
    custom: "some value"
    another: %custom%

then another will be populated with the value of custom , which in my case is "some value". 然后将使用custom的值填充another值,在我的情况下为“某个值”。 My question is, where are these relations documented? 我的问题是,这些关系在哪里记录?

My particular need is to be able to reference an element of an array, something like %somevar[somekey]% , but that syntax doesn't work. 我特别需要的是能够引用数组元素,例如%somevar[somekey]% ,但是该语法不起作用。

Thanks in advance! 提前致谢!

EDIT: I found this: Full merge key support. Full support for references, aliases, and full merge key. Don't repeat yourself by referencing common configuration bits. 编辑:我发现了这一点: Full merge key support. Full support for references, aliases, and full merge key. Don't repeat yourself by referencing common configuration bits. Full merge key support. Full support for references, aliases, and full merge key. Don't repeat yourself by referencing common configuration bits.

in the yaml docs, but no furthur documentation about it.. 在yaml文档中,但没有关于它的进一步文档。

What you are searching for is not really about Yaml itself, but about the Yaml loader of the Dependency Injection container. 您要搜索的不是Yaml本身,而是Dependency Injection容器的Yaml加载器。

If you search docs about it, here are the ones for the old component (v1): http://components.symfony-project.org/dependency-injection/trunk/book/05-Service-Description 如果您搜索有关此文档的文档,则以下是旧组件(v1)的文档: http : //components.symfony-project.org/dependency-injection/trunk/book/05-Service-Description

Symfony2 comes with a new component (based on the same principles). Symfony2带有一个新组件(基于相同的原理)。 You can find the official docs here: http://symfony.com/doc/current/book/service_container.html#service-parameters 您可以在此处找到官方文档: http : //symfony.com/doc/current/book/service_container.html#service-parameters

Concerning your problem, you cannot access to keys of DI parameters, you have to flatten then manually. 关于您的问题,您无法访问DI参数的键,必须先展平然后手动进行。

You could use a DI extension to fit your need, take example on some bundles like: https://github.com/symfony/AsseticBundle/blob/master/DependencyInjection/AsseticExtension.php#L54 (maybe not the best example). 您可以使用DI扩展来满足您的需要,例如在以下捆绑软件中举例: https : //github.com/symfony/AsseticBundle/blob/master/DependencyInjection/AsseticExtension.php#L54 (也许不是最好的例子)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM