8000 [DependencyInjection][CheckTypeDeclarationsPass] Handle unresolved pa… · symfony/symfony@ae185b8 · GitHub
[go: up one dir, main page]

Skip to content

Commit ae185b8

Browse files
committed
[DependencyInjection][CheckTypeDeclarationsPass] Handle unresolved parameters pointing to environment variables
1 parent 51be09c commit ae185b8

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
199199
} elseif (\is_string($value)) {
200200
if ('%' === ($value[0] ?? '') && preg_match('/^%([^%]+)%$/', $value, $match)) {
201201
$value = $this->container->getParameter(substr($value, 1, -1));
202-
} elseif ($envPlaceholderUniquePrefix && false !== strpos($value, 'env_')) {
202+
}
203+
204+
if ($envPlaceholderUniquePrefix && \is_string($value) && false !== strpos($value, 'env_')) {
203205
// If the value is an env placeholder that is either mixed with a string or with another env placeholder, then its resolved value will always be a string, so we don't need to resolve it.
204206
// We don't need to change the value because it is already a string.
205207
if ('' === preg_replace('/'.$envPlaceholderUniquePrefix.'_\w+_[a-f0-9]{32}/U', '', $value, -1, $c) && 1 === $c) {

src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeDeclarationsPassTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -780,17 +780,27 @@ public function testExpressionLanguageWithSyntheticService()
780780

781781
public function testProcessResolveParameters()
782782
{
783-
$container = new ContainerBuilder();
783+
putenv('ARRAY={"foo":"bar"}');
784+
785+
$container = new ContainerBuilder(new EnvPlaceholderParameterBag([
786+
'env_array_param' => '%env(json:ARRAY)%',
787+
]));
784788
$container->setParameter('array_param', ['foobar']);
785789
$container->setParameter('string_param', 'ccc');
786790

787-
$container
788-
->register('foobar', BarMethodCall::class)
791+
$definition = $container->register('foobar', BarMethodCall::class);
792+
$definition
789793
->addMethodCall('setArray', ['%array_param%'])
790794
->addMethodCall('setString', ['%string_param%']);
791795

796+
(new ResolveParameterPlaceHoldersPass())->process($container);
797+
798+
$definition->addMethodCall('setArray', ['%env_array_param%']);
799+
792800
(new CheckTypeDeclarationsPass(true))->process($container);
793801

794802
$this->addToAssertionCount(1);
803+
804+
putenv('ARRAY=');
795805
}
796806
}

0 commit comments

Comments
 (0)
0