Skip to content

[DependencyInjection] [ProxyManager] Use lazy-loading ghost object proxies when possible #46458

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

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented May 25, 2022

Q A
Branch? 6.2
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #35345
License MIT
Doc PR -

This PR makes proxy-manager-bridge use a ghost object proxy by default.

We keep using a value holder proxy:

  • when the lazy definition has the "proxy" tag, since this is the semantics of the tag
  • when the definition declares an abstract type as a "class" (can happen when using a factory)
  • when the proxied class is internal

When a ghost object is initialized, two code paths are possible:

  • if the service is created by constructor, then we call __construct() explicitly on the uninitialized object;
  • if the service is created by a factory, then we copy the state of the object returned by the factory into the ghost object. To do so, we use VarExporter.

@carsonbot carsonbot added this to the 6.2 milestone May 25, 2022
@carsonbot carsonbot changed the title [DependencyInjection][ProxyManager] Use lazy-loading ghost object proxies when possible [DependencyInjection] [ProxyManager] Use lazy-loading ghost object proxies when possible May 25, 2022
@nicolas-grekas nicolas-grekas force-pushed the ghost-proxy branch 3 times, most recently from 13c10d3 to 99d80b0 Compare May 25, 2022 14:12
@nicolas-grekas nicolas-grekas force-pushed the ghost-proxy branch 6 times, most recently from 42d8812 to 1c70a63 Compare May 30, 2022 14:30
@nicolas-grekas
Copy link
Member Author

For what it's worth, this PR works like a charm on a real project :)

@nicolas-grekas
Copy link
Member Author

I updated the PR to keep using a value holder when the proxied class is internal.

nicolas-grekas added a commit that referenced this pull request Jun 22, 2022
…zy loading services (nicolas-grekas)

This PR was merged into the 6.2 branch.

Discussion
----------

[DependencyInjection] Allow using ghost objects for lazy loading services

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

This PR is a subset of #46458 that contains the needed API changes to allow lazy-proxy dumpers to use ghost objects.

The main change of this PR is adding argument `bool &$asGhostObject = null` to LazyProxy's `DumperInterface`.
The rest is the consequence of that new capability.

The changes on ProxyManager are all minor: refactoring the code to make it more flexible (as proved by #46458) and adding the new argument but not doing anything with it (yet.)

Commits
-------

2997693 [DependencyInjection] Allow using ghost objects for lazy loading services
@nicolas-grekas
Copy link
Member Author

Closing in favor of #46752

@nicolas-grekas nicolas-grekas deleted the ghost-proxy branch June 23, 2022 14:22
nicolas-grekas added a commit that referenced this pull request Jul 12, 2022
…oxies out of the box (nicolas-grekas)

This PR was merged into the 6.2 branch.

Discussion
----------

[DependencyInjection] Use lazy-loading ghost object proxies out of the box

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #35345
| License       | MIT
| Doc PR        | -

This PR builds on #46751. It also replaces #46458.

Instead of using ProxyManager to make lazy services actually lazy, using `LazyGhostObjectTrait` from #46751 allows doing so *out of the box* - aka without the need to install any optional dependencies.

When a virtual proxy is required (typically when using [the `proxy` tag](#27697)), ProxyManager is still required (and the dep remains optional.)

But for most services, using `LazyGhostObjectTrait` just works \o/

Commits
-------

58a1848 [DependencyInjection] Use lazy-loading ghost object proxies out of the box
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.

ProxyManagerBridge should possibly use Lazy Loading Ghost Object Proxies instead of Lazy Loading Value Holder Proxies
3 participants