-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] deprecate access to private shared services. #19146
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
hhamon
commented
Jun 22, 2016
•
edited
Loading
edited
Q | A |
---|---|
Branch? | master |
Bug fix? | no |
New feature? | no |
BC breaks? | no |
Deprecations? | yes |
Tests pass? | yes |
Fixed tickets | #19117 |
License | MIT |
Doc PR | ~ |
02e1480
to
9af32f8
Compare
Looks like fabbot gives a false positive! |
But tests are truly broken :) |
|
||
* Requesting a private shared service with the `get()` method of the `Container` | ||
class is no longer supported and will raise an exception. | ||
|
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 also need to add a note in the component CHANGELOG file.
I would have implemented this feature in a different way by renaming internally private services so that their original name is not available from the container (this is what we are doing for anonymous services for instance). |
I think it's a good idea to switch to generated ids in 4.0. For now I like this approach as it allows users to fix their applications more smoothly. |
@@ -198,6 +203,10 @@ public function has($id) | |||
if (--$i && $id !== $lcId = strtolower($id)) { | |||
$id = $lcId; | |||
} else { | |||
if (isset($this->privates[$id])) { | |||
@trigger_error(sprintf('Checking for the existence of the private service "%s" is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0. An exception will be thrown instead in Symfony 4.0.', $id), 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.
Why throw an exception in this case? If you check a private service for existence, the method should return false
, right?
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.
Yes
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.
Yes it makes more sense!
@xabbuh Fair enough, let's keep the current approach for now. |
I'll update the code later today to reflect your comments. |
@@ -176,6 +177,10 @@ public function set($id, $service) | |||
if (null === $service) { | |||
unset($this->services[$id]); | |||
} | |||
|
|||
if (isset($this->privates[$id])) { | |||
@trigger_error(sprintf('Resetting the private service "%s" from outside of the container is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0. An exception will be thrown instead in Symfony 4.0.', $id), 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.
. and
is part of new sentence part and should start with an uppercase 👍
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.
Where is that?
@fabpot generated ids are a good idea for 4.0 indeed, but this cannot be done for deprecations. If we want to switch to generated ids already, we would have to build another feature to to store a mapping between shared private service ids and their generated ids, to retrieve them this way and trigger a deprecation, which would again look like this approach. |
18ba656
to
19f3c66
Compare
I don't understand why the tests suite fails on PHP 5.5 and HHVM. The failing test in the ProxyManager Bridge passes on my machine with PHP 5.5.36... |
@@ -268,6 +281,9 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE | |||
|
|||
return; | |||
} | |||
if (isset($this->privates[$id])) { | |||
@trigger_error(sprintf('Requesting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0. An exception will be thrown instead in Symfony 4.0.', $id), 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.
I won't necessarily throw an exception as it depends on the $invalidBehavior
value.
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.
yes that's right!
The tests are missing for the |
Thanks @Ener-Getick! I'm going to add some ;) |
a43a537
to
13edce2
Compare
I guess it's now ready for another round of reviews if tests pass. |
13edce2
to
326cbeb
Compare
👍 (fabbot fails on a fixture, unrelated) |
no longer supported. Only public services can be set or unset. | ||
|
||
* Checking the existence of a private service with the `Container::has()` | ||
method is no longer supported. |
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.
It's not that it is not supported anymore but more that it's going to return false.
Apart from my minor comment, 👍 |
326cbeb
to
4ed70c4
Compare
@fabpot fixed! CI is running ;) |
Good to go! |
Thank you @hhamon. |
…ed services. (hhamon) This PR was merged into the 3.2-dev branch. Discussion ---------- [DependencyInjection] deprecate access to private shared services. | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #19117 | License | MIT | Doc PR | ~ Commits ------- 4ed70c4 [DependencyInjection] deprecate access to private shared services. Fixes issue #19117.
…rvices (ro0NL) This PR was merged into the 4.0-dev branch. Discussion ---------- [DI] Removed deprecated setting private/pre-defined services | 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 #21533, #19708 and #19146 @nicolas-grekas privates should be excluded from `getServiceIds` right? i also wondered.. did we forget to deprecate checking privates with `initialized()`? Commits ------- 9f96952 [DI] Removed deprecated setting private/pre-defined services