|
19 | 19 | use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
20 | 20 | use Symfony\Component\DependencyInjection\ExpressionLanguage;
|
21 | 21 | use Symfony\Component\DependencyInjection\Parameter;
|
| 22 | +use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag; |
22 | 23 | use Symfony\Component\DependencyInjection\Reference;
|
23 | 24 | use Symfony\Component\DependencyInjection\ServiceLocator;
|
24 | 25 | use Symfony\Component\ExpressionLanguage\Expression;
|
@@ -104,27 +105,29 @@ private function checkTypeDeclarations(Definition $checkedDefinition, \Reflectio
|
104 | 105 | $reflectionParameters = $reflectionFunction->getParameters();
|
105 | 106 | $checksCount = min($reflectionFunction->getNumberOfParameters(), \count($values));
|
106 | 107 |
|
| 108 | + $envPlaceholderUniquePrefix = $this->container->getParameterBag() instanceof EnvPlaceholderParameterBag ? $this->container->getParameterBag()->getEnvPlaceholderUniquePrefix() : null; |
| 109 | + |
107 | 110 | for ($i = 0; $i < $checksCount; ++$i) {
|
108 | 111 | if (!$reflectionParameters[$i]->hasType() || $reflectionParameters[$i]->isVariadic()) {
|
109 | 112 | continue;
|
110 | 113 | }
|
111 | 114 |
|
112 |
| - $this->checkType($checkedDefinition, $values[$i], $reflectionParameters[$i]); |
| 115 | + $this->checkType($checkedDefinition, $values[$i], $reflectionParameters[$i], $envPlaceholderUniquePrefix); |
113 | 116 | }
|
114 | 117 |
|
115 | 118 | if ($reflectionFunction->isVariadic() && ($lastParameter = end($reflectionParameters))->hasType()) {
|
116 | 119 | $variadicParameters = \array_slice($values, $lastParameter->getPosition());
|
117 | 120 |
|
118 | 121 | foreach ($variadicParameters as $variadicParameter) {
|
119 |
| - $this->checkType($checkedDefinition, $variadicParameter, $lastParameter); |
| 122 | + $this->checkType($checkedDefinition, $variadicParameter, $lastParameter, $envPlaceholderUniquePrefix); |
120 | 123 | }
|
121 | 124 | }
|
122 | 125 | }
|
123 | 126 |
|
124 | 127 | /**
|
125 | 128 | * @throws InvalidParameterTypeException When a parameter is not compatible with the declared type
|
126 | 129 | */
|
127 |
| - private function checkType(Definition $checkedDefinition, $value, \ReflectionParameter $parameter): void |
| 130 | + private function checkType(Definition $checkedDefinition, $value, \ReflectionParameter $parameter, ?string $envPlaceholderUniquePrefix): void |
128 | 131 | {
|
129 | 132 | $type = $parameter->getType()->getName();
|
130 | 133 |
|
@@ -178,8 +181,14 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
|
178 | 181 | $value = $this->container->getParameter($value);
|
179 | 182 | } elseif ($value instanceof Expression) {
|
180 | 183 | $value = $this->getExpressionLanguage()->evaluate($value, ['container' => $this->container]);
|
181 |
| - } elseif (\is_string($value) && '%' === ($value[0] ?? '') && preg_match('/^%([^%]+)%$/', $value, $match)) { |
182 |
| - $value = $this->container->getParameter($match[1]); |
| 184 | + } elseif (\is_string($value)) { |
| 185 | + if ($envPlaceholderUniquePrefix && 0 === strpos($value, $envPlaceholderUniquePrefix)) { |
| 186 | + return; |
| 187 | + } |
| 188 | + |
| 189 | + if ('%' === ($value[0] ?? '') && preg_match('/^%([^%]+)%$/', $value, $match)) { |
| 190 | + $value = $this->container->getParameter($match[1]); |
| 191 | + } |
183 | 192 | }
|
184 | 193 |
|
185 | 194 | if (null === $value && $parameter->allowsNull()) {
|
|
0 commit comments