lxg
lxg

Reputation: 13107

Symfony 2.8: bundle aliases in parameters.yml

For a distributable Symfony bundle, I want to allow referencing resource files through parameters.yml.

I want to allow using bundle aliases, e.g. @FoobarSomethingBundle/Resources/foo/bar.png would resolve to src/Foobar/SomethingBundle/Resources/foo/bar.png using Kernel::locateResource.

But apparently I cannot use the leading @ sign to indicate that the reference starts with an alias and is not a file system path per se. For example:

### app/config/parameters.yml
some.value : "@FoobarSomethingBundle/Resources/foo/bar.png"

Symfony would interpret it as a service alias, and clearing the cache would fail with:

[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]                                                                                                          
You cannot dump a container with parameters that contain references to other services (reference to service "foobarsomethingbundle/resources/foo/bar.png" found in "/some.value").

Hence my question: Is there a feature or at least a convention on how to reference bundle aliases in config files, and maybe even resolve them on the fly?

Or maybe there’s a way to inject parameters “literally”, e.g. when I pass "%some.value%" as argument to a service, it would not try to resolve it as a dependency?

Upvotes: 1

Views: 422

Answers (1)

E.K.
E.K.

Reputation: 1055

Just use double @ sign for that

### app/config/parameters.yml
some.value : "@@FoobarSomethingBundle/Resources/foo/bar.png"

Upvotes: 1

Related Questions