Skip to content

[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

Merged
merged 1 commit into from
Jun 29, 2016

Conversation

hhamon
Copy link
Contributor

@hhamon hhamon commented Jun 22, 2016

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 ~

@hhamon
Copy link
Contributor Author

hhamon commented Jun 22, 2016

Looks like fabbot gives a false positive!

@fabpot
Copy link
Member

fabpot commented Jun 23, 2016

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.

Copy link
Member

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.

@fabpot
Copy link
Member

fabpot commented Jun 23, 2016

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

@xabbuh
Copy link
Member

xabbuh commented Jun 23, 2016

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

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?

Copy link
Member

Choose a reason for hiding this comment

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

Yes

Copy link
Contributor Author

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!

@hhamon hhamon changed the title [DependencyInjection] deprecate access to private shared services. [WIP] [DependencyInjection] deprecate access to private shared services. Jun 23, 2016
@fabpot
Copy link
Member

fabpot commented Jun 23, 2016

@xabbuh Fair enough, let's keep the current approach for now.

@hhamon
Copy link
Contributor Author

hhamon commented Jun 23, 2016

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

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 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where is that?

@stof
Copy link
Member

stof commented Jun 23, 2016

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

@hhamon hhamon force-pushed the private-services-fix branch 3 times, most recently from 18ba656 to 19f3c66 Compare June 23, 2016 19:41
@hhamon
Copy link
Contributor Author

hhamon commented Jun 23, 2016

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes that's right!

@GuilhemN
Copy link
Contributor

The tests are missing for the ContainerBuilder :)

@hhamon
Copy link
Contributor Author

hhamon commented Jun 24, 2016

Thanks @Ener-Getick! I'm going to add some ;)

@hhamon hhamon force-pushed the private-services-fix branch 2 times, most recently from a43a537 to 13edce2 Compare June 27, 2016 11:03
@hhamon hhamon changed the title [WIP] [DependencyInjection] deprecate access to private shared services. [DependencyInjection] deprecate access to private shared services. Jun 27, 2016
@hhamon
Copy link
Contributor Author

hhamon commented Jun 27, 2016

I guess it's now ready for another round of reviews if tests pass.

@hhamon hhamon force-pushed the private-services-fix branch from 13edce2 to 326cbeb Compare June 27, 2016 11:13
@nicolas-grekas
Copy link
Member

👍 (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.
Copy link
Member

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.

@fabpot
Copy link
Member

fabpot commented Jun 28, 2016

Apart from my minor comment, 👍

@hhamon hhamon force-pushed the private-services-fix branch from 326cbeb to 4ed70c4 Compare June 28, 2016 07:16
@hhamon
Copy link
Contributor Author

hhamon commented Jun 28, 2016

@fabpot fixed! CI is running ;)

@hhamon
Copy link
Contributor Author

hhamon commented Jun 28, 2016

Good to go!

@fabpot
Copy link
Member

fabpot commented Jun 29, 2016

Thank you @hhamon.

@fabpot fabpot merged commit 4ed70c4 into symfony:master Jun 29, 2016
fabpot added a commit that referenced this pull request Jun 29, 2016
…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.
@fabpot fabpot mentioned this pull request Oct 27, 2016
@hhamon hhamon deleted the private-services-fix branch February 22, 2017 13:13
fabpot added a commit that referenced this pull request Jul 17, 2017
…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
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.

9 participants