Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Description
Symfony version(s) affected
≥ 3.3.7
Description
WhenContainerBuilder::compile
is called with$resolveEnvPlaceholders
, it will end up creating a newParameterBag
from the old one:
symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php
Lines 825 to 827 in05d5bb3
if ($resolveEnvPlaceholders) { | |
$this->parameterBag =newParameterBag($this->resolveEnvPlaceholders($bag->all(),true)); | |
} |
Withtrue
as its second parameter,resolveEnvPlaceholders
will start by calling the bag’sresolveValue
method:
symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php
Lines 1480 to 1482 in05d5bb3
if (true ===$format ??='%%env(%s)%%') { | |
$value =$bag->resolveValue($value); | |
} |
Problem is, at this point the parameter bag already has been resolved by theResolveParameterPlaceHoldersPass
, which means parameters’ value have been unescaped:
$parameters[$key] =$this->unescapeValue($value); |
Since unescaped parameters can appear as if they contain a placeholder, those will trigger aParameterNotFoundException
.
How to reproduce
$builder =newContainerBuilder();$builder->setParameter('foo','%%bar%%');$builder->compile(true);
Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException: You have requested a non-existent parameter "bar".
Possible Solution
I guess an easy fix would be to ignoreParameterNotFoundException
s when creating the newParameterBag
? It feels like addressing a symptom rather than a cause though.
Additional Context
Spotted while investigating#59028.