Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony2 - how can I transfer service into another service in array
    primarykey
    data
    text
    <p>I cannot transfer service into another service in array.</p> <p>For example this is my <code>config.yml</code>:</p> <pre class="lang-yaml prettyprint-override"><code>services: car.price.calculator: class: My\SuperBundle\CarCalculator arguments: "something" product_viewer: car: rest_client: "@car.price.calculator" # &lt;- this is the service I cannot transfer rest_url: http://example.com </code></pre> <p>and <code>service.xml</code>:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" ?&gt; &lt;container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"&gt; &lt;services&gt; &lt;service id="product.browser" class="Mrok\ShopBundle\Price\Calculator"&gt; &lt;argument key="car" type="collection"&gt; &lt;argument key="rest_client"&gt;%product.browser.rest_client%&lt;/argument&gt; &lt;argument key="rest_url"&gt;%product.browser.rest_url%&lt;/argument&gt; &lt;/argument&gt; &lt;/service&gt; &lt;/services&gt; &lt;/container&gt; </code></pre> <p>my MrokShopExtension rewrites data from configuration into container parameters, ex </p> <pre class="lang-php prettyprint-override"><code> $container-&gt;setParameter('product.browser.rest_client', $config[0]['car']['rest_client']); </code></pre> <p><code>Calculator</code> class:</p> <pre><code>class Calculator { private $set; public function __contruct(array $set) { $this-&gt;set = $set; var_dump($set); } </code></pre> <p>and as a result I got (<code>var_dump</code> from code):</p> <pre><code> array (size=2) 'rest_client' =&gt; string '@car.price.calculator' &lt;- and here is a problem, it is a string, should be object </code></pre> <p>How instead of getting the string as <code>rest_client</code> get class instance (service). I cannot change argument into:</p> <pre class="lang-xml prettyprint-override"><code>&lt;argument type="service" id="car.price.calculator" /&gt; </code></pre> <p>because I do not know what kind of service will end user inject. </p> <p>I know I can pass whole container and service id as parameter - but I would like to avoid injecting container.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload