8000 bug #60423 [DependencyInjection] Make `DefinitionErrorExceptionPass` … · symfony/symfony@334bd4f · GitHub
[go: up one dir, main page]

Skip to content

Commit 334bd4f

Browse files
committed
bug #60423 [DependencyInjection] Make DefinitionErrorExceptionPass consider IGNORE_ON_UNINITIALIZED_REFERENCE and RUNTIME_EXCEPTION_ON_INVALID_REFERENCE the same (MatTheCat)
This PR was merged into the 6.4 branch. Discussion ---------- [DependencyInjection] Make `DefinitionErrorExceptionPass` consider `IGNORE_ON_UNINITIALIZED_REFERENCE` and `RUNTIME_EXCEPTION_ON_INVALID_REFERENCE` the same | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #54570 | License | MIT The test container can make runtime errors appear at compile-time: say you have a private definition referenced by a controller. Such a reference would be configured with `RUNTIME_EXCEPTION_ON_INVALID_REFERENCE`, so if the private definition references an errored one, you’d get no exception at compile-time. Now, if this private definition is also referenced by the test container, it would be as `IGNORE_ON_UNINITIALIZED_REFERENCE`. This would change `DefinitionErrorExceptionPass::isErrorForRuntime()` result and trigger a compile-time exception. Following #60423 (comment), this PR makes the `DefinitionErrorExceptionPass` consider `IGNORE_ON_UNINITIALIZED_REFERENCE` the same way than `RUNTIME_EXCEPTION_ON_INVALID_REFERENCE` to fix this issue. Commits ------- 72171c0 [DependencyInjection] Make `DefinitionErrorExceptionPass` consider `IGNORE_ON_UNINITIALIZED_REFERENCE` and `RUNTIME_EXCEPTION_ON_INVALID_REFERENCE` the same
2 parents 255d35f + 72171c0 commit 334bd4f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
6565
}
6666

6767
if ($value instanceof Reference && $this->currentId !== $targetId = (string) $value) {
68-
if (ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior()) {
68+
if (
69+
ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior()
70+
|| ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $value->getInvalidBehavior()
71+
) {
6972
$this->sourceReferences[$targetId][$this->currentId] ??= true;
7073
} else {
7174
$this->sourceReferences[$targetId][$this->currentId] = false;

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

+3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public function testSkipNestedErrors()
6464
$container->register('foo', 'stdClass')
6565
->addArgument(new Reference('bar', ContainerBuilder::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE));
6666

67+
$container->register('baz', 'stdClass')
68+
->addArgument(new Reference('bar', ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE));
69+
6770
$pass = new DefinitionErrorExceptionPass();
6871
$pass->process($container);
6972

0 commit comments

Comments
 (0)
0