Skip to content

Commit 65259c9

Browse files
committed
fix: error with reference, add ID in exception message
1 parent a2eded6 commit 65259c9

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Exception\IncorrectServiceClassException;
18+
use Symfony\Component\DependencyInjection\Reference;
1819

1920
class CheckServiceClassExistsPass implements CompilerPassInterface
2021
{
@@ -26,7 +27,7 @@ public function process(ContainerBuilder $container): void
2627
}
2728

2829
if ($factory = $definition->getFactory()) {
29-
$this->checkFactory($container, $factory);
30+
$this->checkFactory($container, $factory, $id);
3031
continue;
3132
}
3233

@@ -45,14 +46,18 @@ public function process(ContainerBuilder $container): void
4546
}
4647
}
4748

48-
private function checkFactory(ContainerBuilder $container, array|string $factory): void
49+
private function checkFactory(ContainerBuilder $container, array|string $factory, string $id): void
4950
{
51+
if (\is_array($factory) && $factory[0] instanceof Reference && $container->hasDefinition((string) $factory[0])) {
52+
return;
53+
}
54+
5055
$factory = \is_array($factory) ? array_map('strval', $factory) : $container->getParameterBag()->resolveValue($factory);
5156

5257
try {
5358
\Closure::fromCallable($factory);
5459
} catch (\TypeError) {
55-
throw new IncorrectServiceClassException(\sprintf('Factory "%s" is invalid, please check for typos.', \is_string($factory) ? $factory : implode('::', $factory)));
60+
throw new IncorrectServiceClassException(\sprintf('Factory "%s" for service "%s" is invalid, please check for typos.', \is_string($factory) ? $factory : implode('::', $factory), $id));
5661
}
5762
}
5863
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function testProcessParameterClass()
4848
public function testProcessWithFactory()
4949
{
5050
$this->expectException(IncorrectServiceClassException::class);
51-
$this->expectExceptionMessage('Factory "My\MissingClass::create" is invalid, please check for typos.');
51+
$this->expectExceptionMessage('Factory "My\MissingClass::create" for service "foo" is invalid, please check for typos.');
5252

5353
$container = new ContainerBuilder();
5454
$container->register('foo')->setFactory([new Reference('My\MissingClass'), 'create']);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy