Symfony2 passing associative array as argument in service definition issue

Prathap picture Prathap · Apr 24, 2013 · Viewed 13.8k times · Source

I am trying to pass an associative array as argument to a service definition (Solarium, to be precise). However, I get the following error:

"Catchable Fatal Error: Argument 1 passed to Symfony\Component\DependencyInjection\Definition::setArguments() must be of the type array, string given, "

My services.yml reads as follows:

parameters:
    mynamespace.api.solrclient.config: 
        endpoint:
            solrserver:
                host: "search.mysite.com"
                port: "80"
                path: "/solr/"

services:        
    mynamespace.api.solrclient:
        class: Solarium\Client
        arguments: "%mynamespace.api.solrclient.config%"

Is there anything obviously wrong with the way I have defined the parameter array?

Answer

Nuno Costa picture Nuno Costa · Apr 24, 2013

arguments must be an array, try:

services:
    mynamespace.api.solrclient:
        class: Solarium\Client
        arguments: [%mynamespace.api.solrclient.config%]