Let's imagine, that we're developing extremely simple singleton Auth class dealing with DB and session (we don't want any other decomposition like auth adapters etc).
How can I make DI available from this singleton class?
Of course, best way is to pass DI instance to constructor, but what if I want it from singleton? Should I use static setter method Auth::setDi($di) or better practices are available? Or maybe we should avoid singletons because we always have DI storage?
I'm sorry for my english, I hope that my question is clear.
You can access the latest DI instantiated statically:
<?php
$di = Phalcon\DI::getDefault();
http://docs.phalconphp.com/en/latest/reference/di.html#accessing-the-di-in-a-static-way
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With