Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DI] Tagged locator no longer provides service class names as of 4.4.6 #36258

Closed
allcode opened this issue Mar 29, 2020 · 0 comments
Closed

[DI] Tagged locator no longer provides service class names as of 4.4.6 #36258

allcode opened this issue Mar 29, 2020 · 0 comments

Comments

@allcode
Copy link

allcode commented Mar 29, 2020

Symfony version(s) affected: 4.4.6

Description
This issue is regarding a change in functionality of the !tagged_locator (Symfony\Component\DependencyInjection\Argument\ServiceLocator) after updating from 4.4.5 to 4.4.6.

With SF 4.4.5 and earlier, the injected tagged locator provides an array with the alias as key and the FQCN as value when calling getProvidedServices().
As of SF 4.4.6, the FQCN value is replaced with a '?'.

The reason it only provides a '?' is because it now uses a generic Reference instead of a TypedReference for the tagged services. The PhpDumper only adds the service type to the $serviceTypes property of the ServiceLocator if the reference is a TypedReference.

The change is caused by #35957 in \Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait.

Possible Solution
This specific problem can be solved by adding a TypedReference if the resolved class service exists and is not stdClass:

        foreach ($services as [, , $index, $serviceId]) {
            $class = $container->getDefinition($serviceId)->getClass();
            $class = $container->getParameterBag()->resolveValue($class) ?: null;

            if (!$class || 'stdClass' === $class) {
                $reference = new Reference($serviceId);
            } elseif ($index === $serviceId) {
                $reference = new TypedReference($serviceId, $class);
            } else {
                $reference = new TypedReference($serviceId, $class, ContainerBuilder::EXCEPTION_ON_INVALID_REFERENCE, \is_string($index) ? $index : null);
            }

            if (null === $index) {
                $refs[] = $reference;
            } else {
                $refs[$index] = $reference;
            }
        }
@allcode allcode added the Bug label Mar 29, 2020
fabpot added a commit that referenced this issue Mar 30, 2020
…iceTrait (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[DI] fix generating TypedReference from PriorityTaggedServiceTrait

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #36258
| License       | MIT
| Doc PR        | -

Commits
-------

f4dd3e7 [DI] fix generating TypedReference from PriorityTaggedServiceTrait
@fabpot fabpot closed this as completed Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants