10000 Make as many services private as possible by ro0NL · Pull Request #23867 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Make as many services private as possible #23867

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

Make as many services private as possible #23867

wants to merge 1 commit into from

Conversation

ro0NL
Copy link
Contributor
@ro0NL ro0NL commented Aug 11, 2017
Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes/
Tests pass? yes/no
Fixed tickets #23822
License MIT
Doc PR symfony/symfony-docs#...

Proof of concept for a config only approach to upgrade services from public to private. Perfect chance to go with class named services, where possible.

Perhaps, to ease things, we can automate this behavior so in an extension you can do ContainerBuilder::expose(['new_id' => 'old_id']) for example, but i wouldnt make it to big a feature.

Thoughts?

@ro0NL
Copy link
Contributor Author
ro0NL commented Aug 11, 2017

ive added a temp. pass for 3.4 that automates the approach, so we can do all at once and create a single legacy service locator.

@nicolas-grekas
Copy link
Member
nicolas-grekas commented Aug 14, 2017

What about using a tag? (eg "deprecated.public"?)
In a compiler pass, that tag would ensure the services are not inlined (by linking them to two special services, or by making them temporarily lazy, with a second pass removing that lazy attribute - and/or removing that special services on late pass level).

Note that we use a similar pattern in src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml, with a special service named "deprecated.form.registry", so should be updated too.

@ro0NL
Copy link
Contributor Author
ro0NL commented Aug 16, 2017

A tag wont work for aliases right... so it needs to be based on a list of id's i guess.

Either way; this PR seeked for a lazy plan :) but i could give it a try soonish. Still.. for services that we might want to rename anyway this approach is simple and effective.

The proposed feature would be to preserve the id and trigger a custom deprecation message when accessed with get() IIUC.

@ro0NL
Copy link
Contributor Author
ro0NL commented Aug 18, 2017

Quick update after a little discussion with @nicolas-grekas

  • no alias support; effort>gain
  • a upgrade path for services supported till 4.0; we dont wanna maintain logic for it after that as by then you should get this right at first; using the tag is then a no-op.
  • IIUC a tag for private services to preserve public access by referencing those
  • goal is to have them private in 3.4 already

It works; yet there's no deprecation triggered from get(). That requires more work.

@stof
Copy link
Member
stof commented Aug 18, 2017

Well, having no support for such migration path in Symfony 4 makes it unusable for bundles: they cannot switch their services to be private if they need to support Symfony < 3.3 requiring many services to be public. Most bundles won't be able to require Symfony 3.3+ (or even worse 3.4+ for some cases) before the release of 4.0, due to the 2.8 LTS (unless they say that people using 2.8 LTS have to use old releases and give up on bug fixes of the bundle, which may not be fine). Cases requiring 3.4+ are even totally impossible, as 4.0 will be released at the same time.

@nicolas-grekas
Copy link
Member
nicolas-grekas commented Aug 28, 2017

What about this plan:

  • add a tag (container.private?) that express the private-in-next-major state
  • bundles would keep these services as public for <=3.3 compat, but we would turn them private because we can
  • add a compiler pass that turns these into private, with double registration trick to trigger the existing deprecation about private services no being fetchable anymore in 4.0
  • in 4.0, this compiler pass would just turn these services to private
  • in 4.1, we deprecate the container.private tag and the corresponding pass

That would allow bundles to still have the services public with <3.3, trigger the deprecation with 3.4, and have the services really private when used with 4.0.

(I'm still trying to not have to create and maintain a feature to move from pub 8000 lic to private on the long term)

@stof
Copy link
Member
stof commented Aug 31, 2017

@nicolas-grekas that looks good

@Tobion
Copy link
Contributor
Tobion commented Sep 1, 2017

Just some thoughts: The whole concept of private services is only to shrink the container. So basically it's just implementation detail and ideally as developer I should not need to care about this.
So IMO in an ideal world there is no such thing as private and public services.

Can't we achieve that goal? Now that the container creates files per factory, the container should scale better with the amout of services, right? Can't we improve that even more so that the overhead per service is negligible? E.g. less internal tracking of serivce ID mapping to file name/method name.
Then we don't care about private or public at all.

@Tobion
Copy link
Contributor
Tobion commented Sep 1, 2017

I think the only difference are inlined services. If we'd say everything is public, there is no private anymore, the container would need to keep a reference to the inlined services. But does this really matter?

@fabpot
Copy link
Member
fabpot commented Sep 1, 2017

I like @Tobion thoughts a lot :)

@nicolas-grekas
Copy link
Member

In Flex, we made the move of loading everything in the src/ folder because services where private by default - so they would be cleaned up anyway.

@nicolas-grekas
Copy link
Member

Closing as discussed with @ro0NL (who's starting a new job), I'm taking over.
Please continue the discussion on #23822

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
0