-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[DI] Defaults to public=false in all service config files
- Loading branch information
commit 0656284f7fe49418f3417d9f2a996be8ee540603
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
<defaults public="false" /> | ||
|
||
<!-- DataCollector --> | ||
<service id="data_collector.cache" class="Symfony\Component\Cache\DataCollector\CacheDataCollector"> | ||
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. this changes the visibility of this collector. Is it expected ? 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. yes, the service does not need to be public |
||
<tag name="data_collector" template="@WebProfiler/Collector/cache.html.twig" id="cache" priority="275" /> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 through
get
, 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:
symfony/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml
Line 192 in f2f9aa6
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), wh F438 ich 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.
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 :)