Skip to content

[DI] Exclude private services from alternatives #19679

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

Closed
wants to merge 4 commits into from
Closed

[DI] Exclude private services from alternatives #19679

wants to merge 4 commits into from

Conversation

ro0NL
Copy link
Contributor

@ro0NL ro0NL commented Aug 20, 2016

Q A
Branch? "master"
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets comma-separated list of tickets fixed by the PR, if any
License MIT
Doc PR reference to the documentation PR, if any

After #19685 & #19690

@ogizanagi
Copy link
Contributor

This should go into 2.7, not master.

However, you won't be able to exclude privates as Container::privates is only available since 3.2.

try {
$sc->get('int');
$this->fail('->get() throws an Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException if the key does not exist');
} catch (\Exception $e) {
Copy link
Contributor

@ogizanagi ogizanagi Aug 20, 2016

Choose a reason for hiding this comment

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

Why not using @expectedException & @expectedExceptionMessage annotations ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy paste :)

Copy link
Contributor

@ogizanagi ogizanagi Aug 20, 2016

Choose a reason for hiding this comment

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

IMHO, unless there is a good reason, new tests should use the annotations.
When oldest tests where introduced, I guess those annotations (as well as TestCase::setExpectedException()) were not available with the PHPUnit version in use :)

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, new tests should use the annotations.

@ro0NL
Copy link
Contributor Author

ro0NL commented Aug 20, 2016

@ogizanagi could be done :) i dont mind.

@ogizanagi
Copy link
Contributor

ogizanagi commented Aug 20, 2016

@ro0NL: I'd suggest you to create another PR for 2.7 and up, and keep this one to not loose track of the private services handling in 3.2.

@@ -270,6 +270,9 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE

$alternatives = array();
foreach ($this->services as $key => $associatedService) {
if (isset($this->privates[$key])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about moving this check into getServiceIds() and add an optional $private = true argument (which will be deprecated later, in order to the getServiceIds() to only return public services ids ?

Copy link
Contributor Author

@ro0NL ro0NL Aug 20, 2016

Choose a reason for hiding this comment

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

Makes sense for having getServiceIds only expose public id's.

Not sure why we want $private = true. Opposed to refactoring stuff relying on the fact it returns private ids.

We should assume the foreach uses getServiceIds now.

Copy link
Contributor

@ogizanagi ogizanagi Aug 20, 2016

Choose a reason for hiding this comment

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

Not sure why we want $private = true. Opposed to refactoring stuff relying on the fact it returns private ids.

That's only in order to ensure BC. Having this argument set to true should trigger a deprecation. Internally, we'll only use false. (if any internal call needs privates services, we'll have to add another $triggerDeprecation = true argument and set it to false, but I doubt there is.)

We should assume the foreach uses getServiceIds now.

Yes. Why did you change ?

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. Why did you changed ?

Waiting for upstream to change 😛, but ill add it. Makes sense.

Got your point about getServiceIds. It's public API.. which should keep returning privates till 4.0. Ill have a look at it.

if (func_num_args() === 1) {
$includePrivates = !!func_get_arg(0);
if ($includePrivates) {
@trigger_error(sprintf('Including private services in the list of service id\'s is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
Copy link
Contributor Author

@ro0NL ro0NL Aug 20, 2016

Choose a reason for hiding this comment

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

@ogizanagi something like this?

edit: it makes no real sense though.. we can just deprecate privates in getServiceIds on master, right? ie. new/update PR. as it would fix this issue automatically.

Copy link
Contributor

@ogizanagi ogizanagi Aug 20, 2016

Choose a reason for hiding this comment

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

Sorry, I don't understand your concerns 😕 ?

You can't just deprecate privates in getServiceIds if you have no idea the privates were asked. And simply not returning them will be a BC break. Thus, the new argument to explicit the intention, and trigger the deprecation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. master != 4.x this keeps confusing me 😅

{
$includePrivates = true;
if (func_num_args() === 1) {
Copy link
Member

Choose a reason for hiding this comment

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

Nobody calls this with an argument, which means nobody will see the deprecation notice.
Yet, I think we should only add a note to remind about not returning private services in 4.0. No need for any deprecations: if people use the private services returned today from this method, they will get a deprecation because fetching them is deprecated.

@ro0NL
Copy link
Contributor Author

ro0NL commented Aug 22, 2016

Superseded by #19707 + #19685

@ro0NL ro0NL closed this Aug 22, 2016
@ro0NL ro0NL deleted the di/alternative-services branch August 22, 2016 16:26
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.

5 participants