Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d1e31a4

Browse filesBrowse files
committed
bug #35151 [DI] deferred exceptions in ResolveParameterPlaceHoldersPass (Islam93)
This PR was merged into the 3.4 branch. Discussion ---------- [DI] deferred exceptions in ResolveParameterPlaceHoldersPass | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #30428 | License | MIT | Doc PR | n/a fixes case #30428 implemented as in AutowiringPass Commits ------- b3a2173 [DI] deferred exceptions in ResolveParameterPlaceHoldersPass
2 parents c192a0c + b3a2173 commit d1e31a4
Copy full SHA for d1e31a4

File tree

3 files changed

+40
-3
lines changed
Filter options

3 files changed

+40
-3
lines changed

‎src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct()
5353
new ServiceLocatorTagPass(),
5454
new RegisterServiceSubscribersPass(),
5555
new DecoratorServicePass(),
56-
new ResolveParameterPlaceHoldersPass(false),
56+
new ResolveParameterPlaceHoldersPass(false, false),
5757
new ResolveFactoryClassPass(),
5858
new FactoryReturnTypePass($resolveClassPass),
5959
new CheckDefinitionValidityPass(),

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ class ResolveParameterPlaceHoldersPass extends AbstractRecursivePass
2424
{
2525
private $bag;
2626
private $resolveArrays;
27+
private $throwOnResolveException;
2728

28-
public function __construct($resolveArrays = true)
29+
public function __construct($resolveArrays = true, $throwOnResolveException = true)
2930
{
3031
$this->resolveArrays = $resolveArrays;
32+
$this->throwOnResolveException = $throwOnResolveException;
3133
}
3234

3335
/**
@@ -61,7 +63,16 @@ public function process(ContainerBuilder $container)
6163
protected function processValue($value, $isRoot = false)
6264
{
6365
if (\is_string($value)) {
64-
$v = $this->bag->resolveValue($value);
66+
try {
67+
$v = $this->bag->resolveValue($value);
68+
} catch (ParameterNotFoundException $e) {
69+
if ($this->throwOnResolveException) {
70+
throw $e;
71+
}
72+
73+
$v = null;
74+
$this->container->getDefinition($this->currentId)->addError($e->getMessage());
75+
}
6576

6677
return $this->resolveArrays || !$v || !\is_array($v) ? $v : $value;
6778
}

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
1718

1819
class ResolveParameterPlaceHoldersPassTest extends TestCase
1920
{
@@ -71,6 +72,31 @@ public function testBindingsShouldBeResolved()
7172
$this->assertSame($this->container->getParameterBag()->resolveValue('%env(BAZ)%'), $boundValue);
7273
}
7374

75+
public function testParameterNotFoundExceptionsIsThrown()
76+
{
77+
$this->expectException(ParameterNotFoundException::class);
78+
$this->expectExceptionMessage('The service "baz_service_id" has a dependency on a non-existent parameter "non_existent_param".');
79+
80+
$containerBuilder = new ContainerBuilder();
81+
$definition = $containerBuilder->register('baz_service_id');
82+
$definition->setArgument(0, '%non_existent_param%');
83+
84+
$pass = new ResolveParameterPlaceHoldersPass();
85+
$pass->process($containerBuilder);
86+
}
87+
88+
public function testParameterNotFoundExceptionsIsNotThrown()
89+
{
90+
$containerBuilder = new ContainerBuilder();
91+
$definition = $containerBuilder->register('baz_service_id');
92+
$definition->setArgument(0, '%non_existent_param%');
93+
94+
$pass = new ResolveParameterPlaceHoldersPass(true, false);
95+
$pass->process($containerBuilder);
96+
97+
$this->assertCount(1, $definition->getErrors());
98+
}
99+
74100
private function createContainerBuilder()
75101
{
76102
$containerBuilder = new ContainerBuilder();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.