I'm using Symfony 2.4 and it's Expression Language component. In one of my service definitions, I want to use an argument with type="expression". How is it possible to concatenate the following four components using expression language:
service('kernel').getCacheDir() A function result"/" Just a slash%router.cache_class_prefix% A parameter%corebundle.route_provider.cache.class% A parameterI hope I was clear in what I want to achieve. Below you see a part of the services.xml file where I want to use it. But this throws an error: SyntaxError: Unexpected token "string" of value "/" around position 33.
<parameters>
<parameter key="corebundle.route_provider.cache.class">ZikulaRoutes</parameter>
</parameters>
<services>
<service id="corebundle.route_provider" class="%corebundle.route_provider.class%">
<call method="setCachePath">
<argument type="expression">service('kernel').getCacheDir() "/" %router.cache_class_prefix% %corebundle.route_provider.cache.class%</argument>
</call>
</service>
The concatenation operator in the Expression Language is the tilde char ~. The correct syntax for this expression is:
service('kernel').getCacheDir() ~ '/' ~ parameter('router.cache_class_prefix') ~ parameter('corebundle.route_provider.cache.class')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With