8

I wonder where can I get more information about special syntax like @somevar or %somevar% in symfony2's yaml configuration?

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.

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". 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.

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.

in the yaml docs, but no furthur documentation about it..

Tony Bogdanov
  • 7,436
  • 10
  • 49
  • 80

1 Answers1

0

What you are searching for is not really about Yaml itself, but about the Yaml loader of the Dependency Injection container.

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

Symfony2 comes with a new component (based on the same principles). You can find the official docs here: 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.

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).

Florian Klein
  • 8,692
  • 1
  • 32
  • 42
  • Thanks, well actually I just needed to reference parameters inside other parameters, to avoid duplication. So, it's not even up to the DI. I found out that YAML's aliases could do the trick, I just have to tag the entries I need and then reference them as shown in here: http://code.google.com/p/snakeyaml/wiki/Documentation#Aliases Not as flexible as I expected, but will do the trick. Thanks anyway! – Tony Bogdanov Feb 15 '12 at 18:55