Skip to content

Commit 47f37af

Browse files
Merge branch '6.4' into 7.0
* 6.4: [DependencyInjection] Fix computing error messages involving service locators [Serializer] Fix unknown types normalization type when know type [ErrorHandler] Fix parsing messages that contain anonymous classes on PHP >= 8.3.3 [AssetMapper] Fix enquoted string pattern [Validator] Review Romanian (ro) translations [Console] Fix display of Table on Windows OS [FrameworkBundle] Fix config builder with extensions extended in `build()` [Translation] Fix extracting qualified t() function calls Fix vertical table on windows Fix the `command -v` exception when the command option with a dash prefix [WebProfilerBundle] disable turbo in web profiler toolbar to avoid link prefetching explicitly cast boolean SSL stream options return the unchanged text if preg_replace_callback() fails the 'use_notify' option is on the factory, not on the postgres connection class review translations
2 parents 104a824 + 6236e5e commit 47f37af

File tree

3 files changed

+50
-17
lines changed

3 files changed

+50
-17
lines changed

Compiler/AbstractRecursivePass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function processValue(mixed $value, bool $isRoot = false)
7676
continue;
7777
}
7878
if ($isRoot) {
79-
if ($v->hasTag('container.excluded')) {
79+
if ($v instanceof Definition && $v->hasTag('container.excluded')) {
8080
continue;
8181
}
8282
$this->currentId = $k;

Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,7 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
5757
if (isset($this->serviceLocatorContextIds[$currentId])) {
5858
$currentId = $this->serviceLocatorContextIds[$currentId];
5959
$locator = $this->container->getDefinition($this->currentId)->getFactory()[0];
60-
61-
foreach ($locator->getArgument(0) as $k => $v) {
62-
if ($v->getValues()[0] === $value) {
63-
if ($k !== $id) {
64-
$currentId = $k.'" in the container provided to "'.$currentId;
65-
}
66-
throw new ServiceNotFoundException($id, $currentId, null, $this->getAlternatives($id));
67-
}
68-
}
60+
$this->throwServiceNotFoundException($value, $currentId, $locator->getArgument(0));
6961
}
7062

7163
if ('.' === $currentId[0] && $graph->hasNode($currentId)) {
@@ -79,14 +71,21 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
7971
$currentId = $sourceId;
8072
break;
8173
}
74+
75+
if (isset($this->serviceLocatorContextIds[$sourceId])) {
76+
$currentId = $this->serviceLocatorContextIds[$sourceId];
77+
$locator = $this->container->getDefinition($this->currentId);
78+
$this->throwServiceNotFoundException($value, $currentId, $locator->getArgument(0));
79+
}
8280
}
8381
}
8482

85-
throw new ServiceNotFoundException($id, $currentId, null, $this->getAlternatives($id));
83+
$this->throwServiceNotFoundException($value, $currentId, $value);
8684
}
8785

88-
private function getAlternatives(string $id): array
86+
private function throwServiceNotFoundException(Reference $ref, string $sourceId, $value): void
8987
{
88+
$id = (string) $ref;
9089
$alternatives = [];
9190
foreach ($this->container->getServiceIds() as $knownId) {
9291
if ('' === $knownId || '.' === $knownId[0] || $knownId === $this->currentId) {
@@ -99,6 +98,28 @@ private function getAlternatives(string $id): array
9998
}
10099
}
101100

102-
return $alternatives;
101+
$pass = new class() extends AbstractRecursivePass {
102+
public Reference $ref;
103+
public string $sourceId;
104+
public array $alternatives;
105+
106+
public function processValue(mixed $value, bool $isRoot = false): mixed
107+
{
108+
if ($this->ref !== $value) {
109+
return parent::processValue($value, $isRoot);
110+
}
111+
$sourceId = $this->sourceId;
112+
if (null !== $this->currentId && $this->currentId !== (string) $value) {
113+
$sourceId = $this->currentId.'" in the container provided to "'.$sourceId;
114+
}
115+
116+
throw new ServiceNotFoundException((string) $value, $sourceId, null, $this->alternatives);
117+
}
118+
};
119+
$pass->ref = $ref;
120+
$pass->sourceId = $sourceId;
121+
$pass->alternatives = $alternatives;
122+
123+
$pass->processValue($value, true);
103124
}
104125
}

Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,29 +84,41 @@ public function testProcessDefinitionWithBindings()
8484
$this->addToAssertionCount(1);
8585
}
8686

87-
public function testWithErroredServiceLocator()
87+
/**
88+
* @testWith [true]
89+
* [false]
90+
*/
91+
public function testWithErroredServiceLocator(bool $inline)
8892
{
8993
$container = new ContainerBuilder();
9094

9195
ServiceLocatorTagPass::register($container, ['foo' => new Reference('baz')], 'bar');
9296

9397
(new AnalyzeServiceReferencesPass())->process($container);
94-
(new InlineServiceDefinitionsPass())->process($container);
98+
if ($inline) {
99+
(new InlineServiceDefinitionsPass())->process($container);
100+
}
95101

96102
$this->expectException(ServiceNotFoundException::class);
97103
$this->expectExceptionMessage('The service "foo" in the container provided to "bar" has a dependency on a non-existent service "baz".');
98104

99105
$this->process($container);
100106
}
101107

102-
public function testWithErroredHiddenService()
108+
/**
109+
* @testWith [true]
110+
* [false]
111+
*/
112+
public function testWithErroredHiddenService(bool $inline)
103113
{
104114
$container = new ContainerBuilder();
105115

106116
ServiceLocatorTagPass::register($container, ['foo' => new Reference('foo')], 'bar');
107117

108118
(new AnalyzeServiceReferencesPass())->process($container);
109-
(new InlineServiceDefinitionsPass())->process($container);
119+
if ($inline) {
120+
(new InlineServiceDefinitionsPass())->process($container);
121+
}
110122

111123
$this->expectException(ServiceNotFoundException::class);
112124
$this->expectExceptionMessage('The service "bar" has a dependency on a non-existent service "foo".');

0 commit comments

Comments
 (0)