Tobias Hagenbeek
Tobias Hagenbeek

Reputation: 1213

symfony 2 loading sub service by config parameter

I am trying to load a service into another service, using a config param to state the vendor name.

 <service id="test" class="MyClass"> 
      <argument type="service" id="%my.vendor%"></argument>
 </service>
 <service id="vendor.mytest" class="MyServiceClass"></service>

At this point i have confirmed that the %my.vendor% parameter is the string "vendor.mytest", but it is not seen that way, it is literally reading the string %my.vendor% as the "id" of the requested service.

Is there a way to do this, properly...

Thanks!

Upvotes: 1

Views: 88

Answers (1)

Matteo
Matteo

Reputation: 39390

You can use the Expression Language (Available from Symfony 2.4:):

      <service id="test" class="MyClass"> 
        <argument type="expression">service(parameter('my.vendor'))</argument>
    </service>

hope this help

Upvotes: 2

Related Questions