Git Product home page Git Product logo

Comments (3)

Ocramius avatar Ocramius commented on June 27, 2024 1

@mrsuh switching proxy type is feasible within the symfony/dependency-injection system, but is going to be a blood-bath to implement :-)

That would certainly be my recommendation though: I designed ghost objects much after I've designed the initial value-holder design, which got adopted by laminas/laminas-servicemanager, php-di/php-di and symfony/dependency-injection.

Now the path would be to migrate to the newer/better proxy type, but at the cost of added complexity and potential BC issues (the interface on the proxies changes)

from proxymanager.

Ocramius avatar Ocramius commented on June 27, 2024

A couple things:

  1. your HeavyComplexObject (I know it's taken from the examples) should return only itself, when using the static signature: decoration of methods returning : static has always been problematic because of that, and is not really fixable here:
    • declaring HeavyComplexObject in the proxy return type of doFoo() would break the type signature (compile error)
    • returning the proxy itself would break the behavior of doFoo(), swapping out the object at runtime, although we don't know if doFoo() should return the same instance ($this) or a newly instantiated HeavyComplexObject
    • I've described these problems in https://ocramius.github.io/blog/fluent-interfaces-are-evil/ in more detail
  2. for working around most of these problems on fluent interfaces, see https://github.com/Ocramius/ProxyManager/blob/8846623bea8749ded206db3ce701e4e508d516db/docs/lazy-loading-ghost-object.md
    • it is more complex to work with
    • it will preserve the identity of your object, as there is no value holder being wrapped by a proxy, but just the state of the proxy itself
    • it will still break in a declaration like public function doFoo(): static { return new static(); }, since the constructor would need to be final (or interfaced) to work reliably

This cannot be fixed in the library, as there's no declaration (in PHP) that tells us if the same instance, or a new instance, will be returned by doFoo(), so doing this in an automated way is not feasible, and even if we wanted to go into analyzing the AST, we could still have scenarios where this happens conditionally.

My recommendation is to try with ghost objects, linked above.

from proxymanager.

mrsuh avatar mrsuh commented on June 27, 2024

Thank you for detailed answer!
Example works with LazyLoadingGhostFactory.
Maybe It will help for symfony/symfony#46350

from proxymanager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.