-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,7 @@ class Container implements ResettableContainerInterface | |
|
||
protected $services = array(); | ||
protected $methodMap = array(); | ||
protected $privates = array(); | ||
protected $aliases = array(); | ||
protected $loading = array(); | ||
|
||
|
@@ -176,6 +177,14 @@ public function set($id, $service) | |
if (null === $service) { | ||
unset($this->services[$id]); | ||
} | ||
|
||
if (isset($this->privates[$id])) { | ||
if (null === $service) { | ||
@trigger_error(sprintf('Unsetting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED); | ||
} else { | ||
@trigger_error(sprintf('Setting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0. A new public service will be created instead.', $id), E_USER_DEPRECATED); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't keep the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be confusing for people thinking they are overriding a private service but they'll get a new one in the end... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a bad practice imo. Why would someone override a service if it is not synthetic ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @fabpot here, it's the same for private properties on objects btw: they exists from the inside but not from the outside so that one can use the prop name without any collision in a child class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which makes me wonder: is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nicolas-grekas it's useful for synthetic services at least. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we should two different Container classes in Symfony 4.0 instead. Something like a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggested that before when we deprecated calling get() before the container is compiled: #18728 (comment) So yes I would say let's deprecate the method entirely for services that are not synthetic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #19192 |
||
} | ||
} | ||
|
||
/** | ||
|
@@ -198,6 +207,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 "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED); | ||
} | ||
|
||
return method_exists($this, 'get'.strtr($id, $this->underscoreMap).'Service'); | ||
} | ||
} | ||
|
@@ -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.', $id), E_USER_DEPRECATED); | ||
} | ||
|
||
$this->loading[$id] = true; | ||
|
||
|
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.