-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Mark service_container a private service #22806
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
@@ -229,6 +229,8 @@ public function has($id) | |||
{ | |||
for ($i = 2;;) { | |||
if ('service_container' === $id) { | |||
@trigger_error('Checking for the existence of the "service_container" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', 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 3.2?
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.
fixed
@@ -126,7 +126,7 @@ public function __construct(ParameterBagInterface $parameterBag = null) | |||
parent::__construct($parameterBag); | |||
|
|||
$this->trackResources = interface_exists('Symfony\Component\Config\Resource\ResourceInterface'); | |||
$this->setDefinition('service_container', (new Definition(ContainerInterface::class))->setSynthetic(true)); | |||
$this->setDefinition('service_container', (new Definition(parent::class))->setSynthetic(true)->setPublic(false)); |
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.
should we qualify using parent::class
a bugfix?, given https://github.com/ro0NL/symfony/blob/c3e5afa75c820eb4cad0fecc6ddb40055b75a389/src/Symfony/Component/DependencyInjection/ContainerBuilder.php#L1171
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.
nope: the base container class can be changed when the container is dumped
but of course, the base class of ContainerBuilder cannot
so everything is fine, and this change should be reverted
@@ -64,6 +64,10 @@ protected function processValue($value, $isRoot = false) | |||
*/ | |||
private function isInlineableDefinition($id, Definition $definition, ServiceReferenceGraph $graph) | |||
{ | |||
if ('service_container' === $id) { |
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.
same.. probably a bugfix?
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.
service_container was public, so this wouldn't change anything as a bug fix
Given #22866 i think Status: needs work |
@@ -31,6 +31,9 @@ public static function assertSaneContainer(Container $container, $message = '') | |||
{ | |||
$errors = array(); | |||
foreach ($container->getServiceIds() as $id) { | |||
if ('service_container' === $id) { // to be removed in 4.0 |
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.
having to add such check is because there is no way to opt-in in the new behavior of getServiceIds
, and then we have to skip the private services to avoid deprecations later. This causes issues (see also #22866 which faces the same issue).
Can we implement a hidden argument allowing to opt-in for the new behavior instead, to get only public ids ?
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.
Not sure.. wouldnt this be over complex? <4.0 getServiceIds
includes privates, using those with get()
etc. is non-crashing, in >=4.0 those id's are exlcuded as they are crashing. I could live with that.
For the SF codebase i think explicitly skippping is just fine =/
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 is non-crashing, but it triggers deprecation warnings everywhere. And there is no way to avoid this unless you know the ids of all private services (and then, you could as well know the ids of all public services and avoid calling getServiceIds
)
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 think the hidden arg makes sense, it could be added to #22866
@@ -30,6 +30,9 @@ public function __construct() | |||
$this->methodMap = array( | |||
'bar' => 'getBarService', | |||
); | |||
$this->privates = array( | |||
'service_container' => 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.
should we actually dump it in this array ? It receives a special treatment when getting it anyway
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.
Could be left out indeed, but im not sure if we care :) as it requires adding code; which defeats this PR :)
I don't see how it makes the code simpler. It is actually adding code here |
In general i think as of 4.0 it simplifies things :) looking at all checks that can be removed as of 4.0 But more important; i think it's better behavior. |
@@ -39,7 +39,7 @@ public function process(ContainerBuilder $container) | |||
{ | |||
foreach ($container->getDefinitions() as $id => $definition) { | |||
// synthetic service is public | |||
if ($definition->isSynthetic() && !$definition->isPublic()) { | |||
if ($definition->isSynthetic() && !$definition->isPublic() && 'service_container' !== $id) { |
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.
Can be moved before isSynthetic() as this it's faster (micro optimization).
I don't see the point. It makes upgrading more complex, it does not simplify code that much. I'm 👎 for such a change. |
I still think marking it private makes sense... mostly because But yeah.. we dont really need to care about this, and perhaps not worth the effort. Closing for now :) |
follow up of #21627 and marks the
service_container
definition private thus simplifies code, i think it makes sense :)