-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Use ID of the original service when key not specified in service_locator config #48653
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
Conversation
Hey! Thanks for your PR. You are targeting branch "6.3" but it seems your PR description refers to branch "5.4". Cheers! Carsonbot |
aadc68d
to
afb0b40
Compare
use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1; | ||
use Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition2; | ||
|
||
require_once __DIR__.'/../Fixtures/includes/autowiring_classes.php'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I was also in the middle of trying to figure this out, I know why you did this, but probably most people reading this PR will not. I explained the issue here and @chalasr has taken a different approach to avoid referencing the unloaded class.
However, I think we need to take further action with respect to this bug, because this is indicative that we have tests with hidden dependencies and this particular bug has existed for almost 1.5 years undetected. Relying on the happenstance deterministic (alphabetical) ordering of tests is bad because it means tests cannot be run in isolation, which makes development harder. The best way I know to remedy this is to apply executionOrder="random"
to the phpunit.xml
config, which should be done for all such files in this repository.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should document the new method.
@@ -101,6 +92,31 @@ protected function processValue($value, bool $isRoot = false) | |||
return new Reference($id); | |||
} | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my view, this needs documentation to explain what it is doing and why. The method name certainly gives no indication as to what is going on here.
/** | |
/** | |
* Replaces numeric service IDs with service names. |
The method name could probably be improved along these lines, also, e.g. replaceNumericServiceLocatorKeys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion!
} elseif (\is_int($k)) { | ||
$i = null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for?
$services[$k] = $v; | ||
} | ||
|
||
ksort($services); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I knew... I extracted this code for reusing. The ksort()
was removed from the register
method on c67c2df. I have no idea why it still exists in processValue
.
By the way, there is no YAML fixture that actually tests the |
Please target 6.3. As discussed in #48454 this does not qualify as a bugfix but a feature as it is changing a behavior introduced 4 years ago that some people might rely on and some others probably worked around it by specifying keys explicitly.
Agreed. PR welcome to add that missing test case (on the lowest maintained branch where it's applicable, probably 5.4). |
afb0b40
to
064bee1
Compare
Closing as the 7.0 branch does not exist yet. See #48686 |
Dude... what. Even @nicolas-grekas OK'd the 6.x release implicitly in #48454 by stating it's a new feature, which according to the docs, means the target branch is 6.x. |
#48686 implements that feature on 6.x. |
@chalasr @nicolas-grekas |
This is a feature, but we have to take care of compatibility as to not break applications currently relying on the "odd behavior". Stability of behavior and code is the number 1 priority for anything in Symfony. In this case, it is a bit tricky on how to change the behavior in a smooth way (we can't change behavior in 7.0 without a deprecation in 6.x, but we also can't have deprecations in 6.x that can't be fixed). Fortunately, 6.3 is nearly 6 months away still (and 7.0 almost a year from now), so we have all the time to figure out the best path forwards. In any case, #48686 looks like a more promising PR than this one for 6.x (giving it doesn't change behavior). Let's continue finding the best solution in that PR. |
…ce_locator" config (upyx) This PR was merged into the 6.3 branch. Discussion ---------- [DependencyInjection] Deprecate integer keys in "service_locator" config | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | Deprecation befor #48653 | License | MIT | Doc PR | symfony/symfony-docs#17576 It deprecates undefined/wrong behaviour of https://symfony.com/doc/current/service_container/service_subscribers_locators.html#defining-a-service-locator Commits ------- 57c2365 [DependencyInjection] Deprecate integers keys in "service_locator" config
…pyx) This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [DependencyInjection] Remove not implemented behavior Currently numeric keys are used, but it will be deprecated and changed in 7.0. Deprecation: symfony/symfony#48686 New behavior: symfony/symfony#48653 Commits ------- a8770de [DependencyInjection] Remove not implemented behavior
It fixes bug/implementes feature described in #48454