<p dir="auto"><strong>Description</strong><br>
As an enhancement to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="250651797" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/23901" data-hovercard-type="pull_request" data-hovercard-url="/symfony/symfony/pull/23901/hovercard" href="https://github.com/symfony/symfony/pull/23901">#23901</a>, It would be nice to support recursive env var resolution. It is not obvious from the docs or PR (unless i'm missing something), that this is not already supported, so I went around in circles trying to make it work for a while, until Nicolas helped me.</p>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/nicolas-grekas/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/nicolas-grekas">@nicolas-grekas</a></p>
<p dir="auto"><strong>Example</strong><br>
Given environment variables:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="DATABASE_URL=postgres://user:%env(DATABASE_PASSWORD)%@127.0.0.1:5432/database
DATABASE_PASSWORD=foo"><pre class="notranslate">DATABASE_URL=postgres://user:%env(DATABASE_PASSWORD)%@127.0.0.1:5432/database
DATABASE_PASSWORD=foo</pre></div>
<p dir="auto">And some configuration:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="parameters:
    env(DATABASE_PASSWORD): ''
    env(DATABASE_URL): ''

doctrine:
...
   url: '%env(resolve:DATABASE_URL)%'"><pre class="notranslate"><span class="pl-ent">parameters</span>:
    <span class="pl-ent">env(DATABASE_PASSWORD)</span>: <span class="pl-s"><span class="pl-pds">'</span><span class="pl-pds">'</span></span>
    <span class="pl-ent">env(DATABASE_URL)</span>: <span class="pl-s"><span class="pl-pds">'</span><span class="pl-pds">'</span></span>

<span class="pl-ent">doctrine</span>:
...
   <span class="pl-ent">url</span>: <span class="pl-s"><span class="pl-pds">'</span>%env(resolve:DATABASE_URL)%<span class="pl-pds">'</span></span></pre></div>
<p dir="auto"><code class="notranslate">DATABASE_PASSWORD</code> in <code class="notranslate">DATABASE_URL</code> should be resolved, but it is not.</p>
<p dir="auto"><strong>Current Workaround</strong><br>
You must instead use an intermediary parameter:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="DATABASE_URL=postgres://user:%database_password%@127.0.0.1:5432/database
DATABASE_PASSWORD=foo"><pre class="notranslate">DATABASE_URL=postgres://user:%database_password%@127.0.0.1:5432/database
DATABASE_PASSWORD=foo</pre></div>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="parameters:
    database_password: '%env(DATABASE_PASSWORD)'
    env(DATABASE_PASSWORD): ''
    env(DATABASE_URL): ''

doctrine:
...
   url: '%env(resolve:DATABASE_URL)%'"><pre class="notranslate"><span class="pl-ent">parameters</span>:
    <span class="pl-ent">database_password</span>: <span class="pl-s"><span class="pl-pds">'</span>%env(DATABASE_PASSWORD)<span class="pl-pds">'</span></span>
    <span class="pl-ent">env(DATABASE_PASSWORD)</span>: <span class="pl-s"><span class="pl-pds">'</span><span class="pl-pds">'</span></span>
    <span class="pl-ent">env(DATABASE_URL)</span>: <span class="pl-s"><span class="pl-pds">'</span><span class="pl-pds">'</span></span>

<span class="pl-ent">doctrine</span>:
...
   <span class="pl-ent">url</span>: <span class="pl-s"><span class="pl-pds">'</span>%env(resolve:DATABASE_URL)%<span class="pl-pds">'</span></span></pre></div>
<p dir="auto">If you require only the <code class="notranslate">symfony/config</code> component you depend on the <code class="notranslate">symfony/yaml</code> <code class="notranslate">Inline</code> class, which does not show up in the composer <code class="notranslate">require</code> section.</p>
<p dir="auto">Here is a <a href="https://gist.github.com/calinpristavu/d397d64a41c8f2860707">gist</a> with the proof of error. Steps to reproduce:</p>
<ol dir="auto">
<li>require only the config component</li>
<li>run the code in the gist</li>
</ol>
<p dir="auto">In order to solve this, we need to tightly couple the <code class="notranslate">symfony/config</code> component to <code class="notranslate">symfony/yaml</code> or duplicate the <code class="notranslate">Inline::dump()</code> functionality used <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php#L96">here</a> and <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php#L110">here</a> (which is definetly not a good idea IMO).</p>
<p dir="auto">I wanted to make a PR only on the <a href="http://www.github.com/symfony/config">Config component</a> but that one is marked as read-only and add <code class="notranslate">symfony/yaml</code> to the config components <code class="notranslate">config.json</code> require section.</p>
<p dir="auto">Should I make a PR here and add the dependency to the configs <code class="notranslate">composer.json</code> or in the dedicated repo?</p>