Comments (3)
@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.
A couple things:
- your
HeavyComplexObject
(I know it's taken from the examples) should return only itself, when using thestatic
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 ofdoFoo()
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 ifdoFoo()
should return the same instance ($this
) or a newly instantiatedHeavyComplexObject
- I've described these problems in https://ocramius.github.io/blog/fluent-interfaces-are-evil/ in more detail
- declaring
- 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 befinal
(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.
Thank you for detailed answer!
Example works with LazyLoadingGhostFactory
.
Maybe It will help for symfony/symfony#46350
from proxymanager.
Related Issues (20)
- Add PHP 8.1 to CI pipeline HOT 1
- Verify support of `readonly` properties
- Upgrade CI pipeline to fit in a single file
- Integrate dependabot upgrades for PHP and GitHub Actions, including auto-merge
- Add `mixed` type to verified type checks
- Add simple check verifying that proxying an `enum` type fails
- Add scenario for generating proxies for union types in class properties
- Add scenario for generating proxies for intersection types in class properties/parameters/methods
- Verify code generation for the new `never` type HOT 1
- Consider replacing Prefix/suffix interceptor approach with middleware approach HOT 4
- Promoted readonly properties are not respected HOT 7
- Setting property default value to enum points to invalid namespace HOT 12
- AccessInterceptorValueHolder which proxies a parent __get triggers E_USER_NOTICE
- Directly invoking proxy within pre hook crashes terminal HOT 2
- Dependency Dashboard
- Use of mutation testing in ProxyManager - Help needed HOT 1
- Proxies for __set/__unset need special handling if the parent implementation return type is explicitly declared as void HOT 9
- Get returned data of called method HOT 3
- Nullable constructor property promotion support HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proxymanager.