Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
d323232 tod80354dCompare| } | ||
| 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'))); | ||
| } |
nicolas-grekasMay 2, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
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. |
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 would say:Move your child definitions to a different file or define this attribute explicitly.
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.
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"> |
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 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)
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.
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).
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.
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.
nicolas-grekasMay 3, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
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", |
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.
shouldn't it be a normal requirement ? The bundle is all about defining services 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.
In fact, DebugBundle can and is used standalone on Silex, see
https://packagist.org/packages/jeromemacias/silex-debug
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.
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" /> |
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.
@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"> |
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.
this changes the visibility of this collector. Is it expected ?
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.
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", |
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.
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", |
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.
update the requirement lower bound instead
ff6f36a to259a606Comparenicolas-grekas commentedMay 3, 2017
PR should be ready: comments addressed, and integration test case from Ryan added. |
weaverryan commentedMay 3, 2017
I LOVE the idea of eating our own dog food. 👍 for the minor ChildDefinition -> And 👍 for the changes in general. I compiled an XML of the container on |
fabpot commentedMay 3, 2017
Thank you@nicolas-grekas. |
…(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
…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
alcaeus commentedMay 25, 2017
@nicolas-grekas this change seems to have introduced a rather annoying deprecation warning:
This seems to come from the DebugBundle, where the service is injected in a method call using the Apparently, when the compiled container is dumped to a file, this causes a Should the |
nicolas-grekas commentedMay 25, 2017
See#22912 |
alcaeus commentedMay 25, 2017
Ah, my search didn't turn up any results, so I wasn't aware if this was being tracked. Thanks! |
Uh oh!
There was an error while loading.Please reload this page.
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.