-
Notifications
You must be signed in to change notification settings - Fork 11.7k
[12.x] Introduce #[Proxy] attribute
#57974
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
base: 12.x
Are you sure you want to change the base?
Conversation
e975fa8 to
53905ec
Compare
c98bcea to
e7f48eb
Compare
|
@timacdonald Would you mind taking a look at this when you have some time? Not sure about the name... I guess technically the attribute should be |
|
|
||
| $result = null; | ||
|
|
||
| // |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
allow users to mark classes or dependencies which should be built lazily
Building off of @timacdonald's work in #57831
Why would anyone need this
If you've worked in a legacy project, you might've come across junk-drawer service classes that look like this:
When I call
PaymentService@getStripeCustomer(), I am constructing all of the dependencies just to call one of them.In an ideal world, this would be refactored into smaller components with fewer dependencies in each. That's not always a price a development team can pay all at once.
To simplify this, I am proposing introducing a
#[Lazy]attribute, which can be applied to either a class or individual parameters.Naming
Technically this is built using the
proxy()function. I'm not sure that naming the attribute something other than Lazy is worth the distinction.Other ideas
Adding a parameter
bool $dependenciesthat would also make all of the dependencies lazy for the class