minor #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 | #24555
| License       | MIT
| Doc PR        | -

See linked issue.

Commits
-------

fdb0ea9 [DI] Enhance service locator error message
This commit is contained in:
Nicolas Grekas 2017-10-20 12:00:26 -07:00
commit beed426e9a

View File

@ -78,6 +78,9 @@ final class ServiceLocatorTagPass extends AbstractRecursivePass
public static function register(ContainerBuilder $container, array $refMap)
{
foreach ($refMap as $id => $ref) {
if (!$ref instanceof Reference) {
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));
}
$refMap[$id] = new ServiceClosureArgument($ref);
}
ksort($refMap);