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

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

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

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedJun 23, 2022
edited
Loading

QA
Branch?6.2
Bug fix?no
New feature?yes
Deprecations?no
TicketsFix#35345
LicenseMIT
Doc PR-

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

Instead of using ProxyManager to make lazy services actually lazy, usingLazyGhostObjectTrait from#46751 allows doing soout of the box - aka without the need to install any optional dependencies.

When a virtual proxy is required (typically when usingtheproxy tag), ProxyManager is still required (and the dep remains optional.)

But for most services, usingLazyGhostObjectTrait just works \o/

@nicolas-grekasnicolas-grekasforce-pushed thedi-ghost-objects branch 9 times, most recently fromdf1a745 to830a069CompareJuly 1, 2022 14:30
@nicolas-grekasnicolas-grekasforce-pushed thedi-ghost-objects branch 6 times, most recently from5a18093 to5739354CompareJuly 11, 2022 06:32
@nicolas-grekas
Copy link
MemberAuthor

PR rebased and ready \o/

@nicolas-grekasnicolas-grekas merged commitd095a50 intosymfony:6.2Jul 12, 2022
@nicolas-grekasnicolas-grekas deleted the di-ghost-objects branchJuly 12, 2022 15:57
nicolas-grekas added a commit to symfony/orm-pack that referenced this pull requestJul 12, 2022
fabpot added a commit that referenced this pull requestSep 3, 2022
…ng virtual proxies for non-ghostable lazy services (nicolas-grekas)This PR was merged into the 6.2 branch.Discussion----------[DependencyInjection][VarExporter] Generate lazy-loading virtual proxies for non-ghostable lazy services| Q             | A| ------------- | ---| Branch?       | 6.2| Bug fix?      | no| New feature?  | yes| Deprecations? | no| Tickets       | -| License       | MIT| Doc PR        | -Since#46752 and#46751, we are able to make services lazy out of the box, except when 1. a service relies on an internal class 2. a service has the `proxy` tag or 3. a service's class is abstract (and the service uses a factory). In these situations, proxy-manager-bridge was required. This was an acceptable trade-off because this would be quite uncommon. But while working on Doctrine, I realized that we cannot use ghost objects when a factory is used. I described this for Doctrine indoctrine/orm#9896 but the situation can happen with any services constructed by a factory. This means we'd need proxy-manager-bridge anytime a factory is used on a lazy service. What was uncommon becomes quite common and the trade-off is not acceptable anymore. Thus this PR.This PR adds a `LazyProxyTrait` and a `ProxyHelper` to build lazy loading virtual proxies at will. It then wires this new capability into the container. As a result proxy-manager-bridge is not needed anymore. We can deprecate it in another PR.While the diff is quite big,  `LazyProxyTrait` has many similarities with `LazyGhostTrait` and both traits can be diffed to see where their behavior varies.Excerpt from the [README](https://github.com/nicolas-grekas/symfony/blob/ve-inheritance-proxy/src/Symfony/Component/VarExporter/README.md) for the record:>The component provides two lazy loading patterns: ghost objects and virtual proxies (seehttps://martinfowler.com/eaaCatalog/lazyLoad.html for reference.)>>Ghost objects work only on concrete and non-internal classes. In the generic case, they are not compatible with using factories in their initializer.>>Virtual proxies work on concrete, abstract or internal classes. They provide an API that looks like the actual objects and forward calls to them. They can cause identity problems because proxies might not be seen as equivalents to the actual objects.>>Because of this identity problem, ghost objects should be preferred when possible. Exceptions thrown by the ProxyHelper class can help decide when it can be used or not.>>Ghost objects and virtual proxies both provide implementations for the LazyObjectInterface which allows resetting them to their initial state or to forcibly initialize them when needed. Note that resetting a ghost object skips its read-only properties. You should use a virtual proxy to reset read-only properties.Commits-------4862139 [DependencyInjection][VarExporter] Generate lazy proxies for non-ghostable lazy services out of the box
@fabpotfabpot mentioned this pull requestOct 24, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@chalasrchalasrchalasr approved these changes

@wouterjwouterjAwaiting requested review from wouterjwouterj is a code owner

+1 more reviewer

@TobionTobionTobion left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

6.2

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

5 participants

@nicolas-grekas@stof@Tobion@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp