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