Skip to content

[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

Merged
merged 1 commit into from
Jan 11, 2017

Conversation

nicolas-grekas
Copy link
Member

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.

@@ -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)])) {
Copy link
Member

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

Copy link
Member Author

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);
Copy link
Member

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 ?

Copy link
Member Author

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()) {
Copy link
Member

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 ?

Copy link
Member Author

@nicolas-grekas nicolas-grekas Jan 10, 2017

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;
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for Alias btw

@nicolas-grekas nicolas-grekas force-pushed the di-case-sensitive branch 5 times, most recently from 99f285f to 9e1dbff Compare January 10, 2017 14:36
@nicolas-grekas
Copy link
Member Author

PR ready for second review

@fabpot
Copy link
Member

fabpot commented Jan 10, 2017

You need to also update UPGRADE-4.0.md

@@ -22,7 +22,12 @@ class Alias
*/
public function __construct($id, $public = true)
{
$this->id = strtolower($id);
if (!is_string($id)) {
Copy link
Contributor

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.

Copy link
Member Author

@nicolas-grekas nicolas-grekas Jan 10, 2017

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fine for me :)

Copy link
Contributor

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);
Copy link
Contributor

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..

Copy link
Member Author

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 :)

Copy link
Contributor

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.

@nicolas-grekas
Copy link
Member Author

UPGRADE-4.0.md updated

@fabpot
Copy link
Member

fabpot commented Jan 11, 2017

Thank you @nicolas-grekas.

@fabpot fabpot merged commit d08f110 into symfony:master Jan 11, 2017
fabpot added a commit that referenced this pull request Jan 11, 2017
… (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
@nicolas-grekas nicolas-grekas deleted the di-case-sensitive branch January 13, 2017 20:07
@fabpot fabpot mentioned this pull request May 1, 2017
nicolas-grekas added a commit that referenced this pull request Jul 11, 2017
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants