8000 minor #24582 [DI] Enhance service locator error message (nicolas-grekas) · alexpott/symfony@beed426 · GitHub
[go: up one dir, main page]

Skip to content

Commit beed426

Browse files
minor symfony#24582 [DI] Enhance service locator error message (nicolas-grekas)
This PR was merged into the 3.3 branch. Discussion ---------- [DI] Enhance service locator error message | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#24555 | License | MIT | Doc PR | - See linked issue. Commits ------- fdb0ea9 [DI] Enhance service locator error message
2 parents 402246e + fdb0ea9 commit beed426

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ protected function processValue($value, $isRoot = false)
7878
public static function register(ContainerBuilder $container, array $refMap)
7979
{
8080
foreach ($refMap as $id => $ref) {
81+
if (!$ref instanceof Reference) {
82+
throw new InvalidArgumentException(sprintf('Invalid service locator definition: only services can be referenced, "%s" found for key "%s". Inject parameter values using constructors instead.', is_object($ref) ? get_class($ref) : gettype($ref), $id));
83+
}
8184
$refMap[$id] = new ServiceClosureArgument($ref);
8285
}
8386
ksort($refMap);

0 commit comments

Comments
 (0)
0