Why using ProxyManager?

I did read Ocramius/ProxyManager docs and examples serveral times carefully. If you clarify this then I am just fine:

Assuming we don’t have a DI in a class and our class is just something simple with a slow costructor with some getters/setters method, it makes sense to use for example a Virtual proxy, if we want to initiate the class first but call the method probably later, as in some scripts of the product no method is never called, so the initiation without proxy was useless and waste of time.

But if in a script we call the class and immediately after initiation we call the methods, assuming that is the only script of the product where calling the class, it does not much make sense to use a proxy? Right? I greatly appreciate if you clarify if my assumption is right or please advise.


1 Like

You are correct.

The classic example is a mailer object which typically has a heavy constructor. You might have some code where you only send mail if certain conditions are met. If so, you might inject a proxy for the mailer to avoid constructing the heavy object if no mailing is needed.

On the other hand, if you know that emails will always be sent then there is no point in incurring the cost of a proxy object. Always a trade off.

For example having in start e.g. in a core file

$email = new phpMailer(.....);

and that core file is always required in start of all scripts but not necessarily sending an email?

So if we don’t have it in core file but in e.g. create account page then will send email surely then proxy is useless?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.