Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da0e2c3

Browse files
committed
[DependencyInjection][CheckTypeDeclarationsPass] Always resolve parameters
1 parent c70241e commit da0e2c3

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
198198
}
199199
} elseif (\is_string($value)) {
200200
if ('%' === ($value[0] ?? '') && preg_match('/^%([^%]+)%$/', $value, $match)) {
201-
// Only array parameters are not inlined when dumped.
202-
$value = [];
201+
$value = $this->container->getParameter(substr($value, 1, -1));
203202
} elseif ($envPlaceholderUniquePrefix && false !== strpos($value, 'env_')) {
204203
// 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.
205204
// We don't need to change the value because it is already a string.

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -612,20 +612,6 @@ public function testProcessThrowsOnIterableTypeWhenScalarPassed()
612612
$this->assertInstanceOf(\stdClass::class, $container->get('bar')->foo);
613613
}
614614

615-
public function testProcessResolveArrayParameters()
616-
{
617-
$container = new ContainerBuilder();
618-
$container->setParameter('ccc', ['foobar']);
619-
620-
$container
621-
->register('foobar', BarMethodCall::class)
622-
->addMethodCall('setArray', ['%ccc%']);
623-
624-
(new CheckTypeDeclarationsPass(true))->process($container);
625-
626-
$this->addToAssertionCount(1);
627-
}
628-
629615
public function testProcessResolveExpressions()
630616
{
631617
$container = new ContainerBuilder();
@@ -791,4 +777,20 @@ public function testExpressionLanguageWithSyntheticService()
791777

792778
$this->addToAssertionCount(1);
793779
}
780+
781+
public function testProcessResolveParameters()
782+
{
783+
$container = new ContainerBuilder();
784+
$container->setParameter('array_param', ['foobar']);
785+
$container->setParameter('string_param', 'ccc');
786+
787+
$container
788+
->register('foobar', BarMethodCall::class)
789+
->addMethodCall('setArray', ['%array_param%'])
790+
->addMethodCall('setString', ['%string_param%']);
791+
792+
(new CheckTypeDeclarationsPass(true))->process($container);
793+
794+
$this->addToAssertionCount(1);
795+
}
794796
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/CheckTypeDeclarationsPass/BarMethodCall.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,8 @@ public function setCallable(callable $callable): void
4444
public function setClosure(\Closure $closure): void
4545
{
4646
}
47+
48+
public function setString(string $string)
49+
{
50+
}
4751
}

0 commit comments

Comments
 (0)