Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Closed
wants to merge 1 commit into from
Closed

[DI] Mark service_container a private service #22806

wants to merge 1 commit into from

Conversation

ro0NL
Copy link
Contributor

@ro0NL ro0NL commented May 20, 2017

Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets #...
License MIT
Doc PR symfony/symfony-docs#...

follow up of #21627 and marks the service_containerdefinition private thus simplifies code, i think it makes sense :)

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

Choose a reason for hiding this comment

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

Why 3.2?

Copy link
Contributor Author

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

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

Choose a reason for hiding this comment

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

same.. probably a bugfix?

Copy link
Member

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

@nicolas-grekas nicolas-grekas modified the milestone: 3.4 May 21, 2017
@nicolas-grekas nicolas-grekas self-requested a review May 22, 2017 06:58
@ro0NL
Copy link
Contributor Author

ro0NL commented May 24, 2017

Given #22866 i think ContainerBuilder::get('service_container') should remain working; lets be consistent :)

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

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 ?

Copy link
Contributor Author

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 =/

Copy link
Member

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)

Copy link
Member

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,
Copy link
Member

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

Copy link
Contributor Author

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

@stof
Copy link
Member

stof commented May 24, 2017

I don't see how it makes the code simpler. It is actually adding code here

@nicolas-grekas nicolas-grekas removed their request for review May 24, 2017 09:12
@ro0NL
Copy link
Contributor Author

ro0NL commented May 24, 2017

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

@sstok sstok May 26, 2017

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

@fabpot
Copy link
Member

fabpot commented Jul 4, 2017

I don't see the point. It makes upgrading more complex, it does not simplify code that much. I'm 👎 for such a change.

@ro0NL
Copy link
Contributor Author

ro0NL commented Jul 4, 2017

I still think marking it private makes sense... mostly because $container->get('service_container') doesnt :) (AFAIK this would be the only upgrade step, using $container directly in that case).

But yeah.. we dont really need to care about this, and perhaps not worth the effort. Closing for now :)

@ro0NL ro0NL closed this Jul 4, 2017
@ro0NL ro0NL deleted the di/private-service-container branch July 4, 2017 09:47
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.

7 participants