Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DI] Defaults to public=false in all service config files#22615

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:masterfromnicolas-grekas:di-defaults
May 3, 2017

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedMay 2, 2017
edited
Loading

QA
Branch?3.3
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets-
LicenseMIT
Doc PR-

This is what we call "eating your own dog food" :)
Made me realize that we need a tweak to the defaults<>ChildDefinition conflict we have now:
tags should be applied, and there should beno conflict when everything is setexplicitly on the child definition.

theofidry, ro0NL, ogizanagi, linaori, chalasr, and apfelbox reacted with thumbs up emojitheofidry reacted with hooray emoji
}
if (!$service->hasAttribute($k)) {
thrownewInvalidArgumentException(sprintf('Attribute "%s" on service "%s" cannot be inherited from "defaults" when a "parent" is set. Try moving your child definitions to a different file or defining this attribute explicitly.',$k,$service->getAttribute('id')));
}
Copy link
MemberAuthor

@nicolas-grekasnicolas-grekasMay 2, 2017
edited
Loading

Choose a reason for hiding this comment

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

this block is the main and only behavior change of this PR (same on YamlFileLoader)

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessageThe service "child_service" cannot use the "parent" option in the same file where"defaults"configuration is defined as using bothisnot supported. Try moving your child definitions to a different file.
* @expectedExceptionMessageAttribute "autowire" on service "child_service" cannot be inherited from"defaults"when a "parent"isset. Try moving your child definitions to a different file or defining this attribute explicitly.
Copy link
Member

Choose a reason for hiding this comment

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

I would say:Move your child definitions to a different file or define this attribute explicitly.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

updated (and test case added)

</service>

<serviceid="debug.dump_listener"class="Symfony\Component\HttpKernel\EventListener\DumpListener">
<serviceid="debug.dump_listener"class="Symfony\Component\HttpKernel\EventListener\DumpListener"public="true">
Copy link
Member

Choose a reason for hiding this comment

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

it would be great to be able to change this service to become private in 4.0 (as event listeners can now be private).
@nicolas-grekas I thnk a necessary feature for 3.4 would be a way to mark a service as "wanna-be-private", which would trigger a deprecation warning when getting it from the container throughget, but not when injecting it inside another service (unlike deprecated services). Such feature would allow any bundle out there to provide gradual migration to private services (warning people if they try to access internal services that will become private)

ogizanagi, chalasr, linaori, sstok, and yceruto reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

100% agree, and this PR is on that path :)
No need for any new feature as there is already a trick to do the deprecation, see:

<serviceid="deprecated.form.registry"class="stdClass">

So, we should just turn these services as private, then register them in a public dummy registry, that will prevent inlining and will thus make them "public" (but in a deprecated manner).

Copy link
Member

Choose a reason for hiding this comment

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

no, the form types are deprecating the services entirely, because they won't be needed anymore in 4.0 (form types without any dependencies don't need to be registered explicitly anymore).

But we might have a case where we want to deprecate the runtime retrieval of services (to make them private) without deprecating the service itself (as you will want to keep it as a dependency of other services), which is what we need for listeners.

And making them public in a deprecated manner works for Symfony services in 3.4.x. but it does not work for the future of Symfony, because your proposal relies on the BC layer for accessing non-inlined private services. But Symfony 4 will not make such services public at all, even when not inlined, and so you cannot have a similar BC layer for the migration to private services.

Btw, if you want to be sure that the services stay public, you must create 2 dummy registries. If you create only one, the service may end up being inlined inside the dummy registry if other references get removed by some optimizations.

Copy link
MemberAuthor

@nicolas-grekasnicolas-grekasMay 3, 2017
edited
Loading

Choose a reason for hiding this comment

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

The form types I linked are the ones that are not deprecated because they need special instantiation.
You're right that this trick is valid only on 3.4. But maybe 3.4 is the last one that will have public services? So if using the trick is enough for 3.4, then maybe better not to work on a new feature for nothing?

Anyway, that's an interesting discussion, but should not be hidden in this PR :)

"require-dev": {
"symfony/config":"~2.8|~3.0",
"symfony/dependency-injection":"~2.8|~3.0",
"symfony/dependency-injection":"~3.3",
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't it be a normal requirement ? The bundle is all about defining services anyway.

sstok reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

In fact, DebugBundle can and is used standalone on Silex, see
https://packagist.org/packages/jeromemacias/silex-debug

Copy link
Member

Choose a reason for hiding this comment

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

hmm indeed, they get it to get the template for the profiler, which is not in WebProfilerBundle unlike other collectors

</call>
</service>
<serviceid="Doctrine\Common\Annotations\Reader"alias="annotations.reader"public="false"/>
<serviceid="Doctrine\Common\Annotations\Reader"alias="annotations.reader" />
Copy link
Member

Choose a reason for hiding this comment

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

@nicolas-grekas this autowiring alias should point toannotation_reader, which is the public name for it (even though it is an alias), so that people decorating the public name still get it applied in case of autowiring.

<defaultspublic="false" />

<!-- DataCollector-->
<serviceid="data_collector.cache"class="Symfony\Component\Cache\DataCollector\CacheDataCollector">
Copy link
Member

Choose a reason for hiding this comment

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

this changes the visibility of this collector. Is it expected ?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

yes, the service does not need to be public

"phpunit/phpunit":"<4.8.35|<5.4.3,>=5.0",
"symfony/asset":"<3.3",
"symfony/console":"<3.3",
"symfony/dependency-injection":"<=3.3-beta1",
Copy link
Member

Choose a reason for hiding this comment

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

As we have a requirement on it, just update the lower bound of the requirement. It is more efficient in the composer solver than adding a conflict rule.

"twig/twig":"~1.28|~2.0"
},
"conflict": {
"symfony/dependency-injection":"<=3.3-beta1",
Copy link
Member

Choose a reason for hiding this comment

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

update the requirement lower bound instead

@nicolas-grekasnicolas-grekasforce-pushed thedi-defaults branch 3 times, most recently fromff6f36a to259a606CompareMay 3, 2017 15:52
@nicolas-grekas
Copy link
MemberAuthor

PR should be ready: comments addressed, and integration test case from Ryan added.

@weaverryan
Copy link
Member

I LOVE the idea of eating our own dog food.

👍 for the minor ChildDefinition ->_defaults behavior change. You can see the new behavior by comparingmain.yml toexpected.yml in the integration test:https://github.com/symfony/symfony/pull/22615/files#diff-e36b91c9d48d3617ee8a401577fcc603. Having a child definition in the same file as_defaults wasn't allowed at ALL anymore. Now it is, but only if you explicitly set any keys from_defaults on the child (i.e. we force you to override_defaults values (other than tags) so that there is no ambiguity).

And 👍 for the changes in general. I compiled an XML of the container onmaster versus this branch. They are identical, other thandata_collector.cache, which was purposefully changed frompublic toprivate:https://gist.github.com/weaverryan/353a79c0e310b59d5eca9c922bc5cf5f

ogizanagi reacted with thumbs up emoji

@fabpot
Copy link
Member

Thank you@nicolas-grekas.

@fabpotfabpot merged commit0656284 intosymfony:masterMay 3, 2017
fabpot added a commit that referenced this pull requestMay 3, 2017
…(nicolas-grekas)This PR was merged into the 3.3-dev branch.Discussion----------[DI] Defaults to public=false in all service config files| Q             | A| ------------- | ---| Branch?       | 3.3| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -This is what we call "eating your own dog food" :)Made me realize that we need a tweak to the defaults<>ChildDefinition conflict we have now:tags should be applied, and there should be *no* conflict when everything is set *explicitly* on the child definition.Commits-------0656284 [DI] Defaults to public=false in all service config files
@nicolas-grekasnicolas-grekas deleted the di-defaults branchMay 4, 2017 12:17
fabpot added a commit that referenced this pull requestMay 13, 2017
…ublic (ogizanagi)This PR was merged into the 3.3-dev branch.Discussion----------[TwigBundle] service workflow.twig_extension should stay public| Q             | A| ------------- | ---| Branch?       | master (3.3)| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | N/A| License       | MIT| Doc PR        | N/AWhile it's not really required for this service to be public AFAIK, it was not made private when introducing it in 3.2. Which means it should stay public in upper branches. But [since we now default to `public: false`](#22615) in every service config file, it's currently private in 3.3.I had a quick look on commits merged after this PR and didn't find any other similar case.Commits-------5d07c6a [TwigBundle] service workflow.twig_extension should stay public
@fabpotfabpot mentioned this pull requestMay 17, 2017
@alcaeus
Copy link
Contributor

@nicolas-grekas this change seems to have introduced a rather annoying deprecation warning:

Checking for the existence of the "debug.file_link_formatter" private service is deprecated since Symfony 3.2 and won't be supported anymore in Symfony 4.0: (383x)

This seems to come from the DebugBundle, where the service is injected in a method call using theon-invalid=ignore flag:

        <service>            <argument>null</argument>            <argument>%kernel.charset%</argument>            <argument>0</argument> <!-- flags -->            <call method="setDisplayOptions">                <argument type="collection">                    <argument key="fileLinkFormat" type="service" on-invalid="ignore"></argument>                </argument>            </call>        </service>

Apparently, when the compiled container is dumped to a file, this causes a$container->has call on the private service.

    protected function getTwigService()    {        // ...        $d = new \Symfony\Component\VarDumper\Dumper\HtmlDumper(NULL, 'UTF-8', 0);        if ($this->has('debug.file_link_formatter')) {            $d->setDisplayOptions(array('fileLinkFormat' => $b));        }        // ...    }

Should thedebug.file_link_formatter service be made public or are you intending to ship 3.3 with this deprecation?

@nicolas-grekas
Copy link
MemberAuthor

See#22912

@alcaeus
Copy link
Contributor

Ah, my search didn't turn up any results, so I wasn't aware if this was being tracked. Thanks!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot left review comments

@stofstofstof requested changes

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

6 participants

@nicolas-grekas@weaverryan@fabpot@alcaeus@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp