-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Deprecate case insentivity of service identifiers #21223
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
@@ -51,12 +51,12 @@ public function process(ContainerBuilder $container) | |||
private function updateDefinition(ContainerBuilder $container, $id, Definition $definition, array $resolveClassPassChanges, array $previous = array()) | |||
{ | |||
// circular reference | |||
if (isset($previous[$id])) { | |||
if (isset($previous[$lcId = strtolower($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.
I would move $lcId = strtolower($id)
on its own statement. It would be more readable
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.
fixed, other comments addressed also
@@ -407,7 +398,7 @@ public function removeDefinition($id) | |||
*/ | |||
public function has($id) | |||
{ | |||
$id = strtolower($id); | |||
$id = $this->normalizeId($id); | |||
|
|||
return isset($this->definitions[$id]) || isset($this->aliasDefinitions[$id]) || parent::has($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.
shoudln't we pass the original value to the parent call ?
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.
this would only trigger a second deprecation, nothing else
@@ -1246,8 +1221,8 @@ private function callMethod($service, $call) | |||
*/ | |||
private function shareService(Definition $definition, $service, $id) | |||
{ | |||
if ($definition->isShared()) { | |||
$this->services[$lowerId = strtolower($id)] = $service; | |||
if (null !== $id && $definition->isShared()) { |
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.
when can it be 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.
because of eg $this->createService($value, null)
in the code
@@ -29,7 +29,7 @@ class Reference | |||
*/ | |||
public function __construct($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) | |||
{ | |||
$this->id = strtolower($id); | |||
$this->id = $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.
we still need to cast to string here (with a deprecation), otherwise __toString
will be broken
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.
same for Alias btw
99f285f
to
9e1dbff
Compare
PR ready for second review |
9e1dbff
to
99083df
Compare
You need to also update |
@@ -22,7 +22,12 @@ class Alias | |||
*/ | |||
public function __construct($id, $public = true) | |||
{ | |||
$this->id = strtolower($id); | |||
if (!is_string($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.
Do we really need this? The docblock already specifies that it must be string.
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.
That's what was said also about container->get, then I had to explicitly add string casts in our own tests. So, yes: a BC layer is a friendly default policy.
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.
Ok, fine for me :)
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.
@nicolas-grekas just finished mine :).. probably related. Not sure i follow.. but ill dig in :)
if (!is_string($id)) { | ||
$type = is_object($id) ? get_class($id) : gettype($id); | ||
$id = (string) $id; | ||
@trigger_error(sprintf('Non-string service identifiers are deprecated since Symfony 3.3 and won\'t be supported in 4.0 for service "%s" ("%s" given.) Cast it to string beforehand.', $id, $type), E_USER_DEPRECATED); |
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.
At this point we dont really know what the case of the non-string-service-id is right? Meaning this deprecation can be a false positive?
Ie. $normalizedId = strtolower((string) $id)
looks sufficient? Triggering deprecation as usual from below..
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.
You should read the deprecation message twice, same for your other comments :)
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.
Holy crap.. i got it :) Sorry.
99083df
to
d08f110
Compare
UPGRADE-4.0.md updated |
Thank you @nicolas-grekas. |
… (nicolas-grekas) This PR was merged into the 3.3-dev branch. Discussion ---------- [DI] Deprecate case insentivity of service identifiers | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | minor (see UPGRADE note) | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #21193 | License | MIT | Doc PR | - As discussed in linked RFC. Commits ------- d08f110 [DI] Deprecate case insentivity of service identifiers
…o0NL) This PR was squashed before being merged into the 4.0-dev branch (closes #22811). Discussion ---------- [DI] Remove deprecated case insensitive service ids | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> See #21223 Commits ------- 63e26fc [DI] Remove deprecated case insensitive service ids
As discussed in linked RFC.