Is the Service unresolved in DI?

I have my DI container with custom service in it:

$di = new Phalcon\Di;
$di->set('whatever', function(){
    return new Whatever();
}, true); // It is shared.

Shared service "whatever" may or may not be resolved (instantiated/set) by my application.

At the end of request cycle I need to know whether it was resolved or not.

Obviously, I don't want to do:


because that will resolve it for sure.

Is there a way of knowing whether "whatever" has been resolved?

Thanks, Temuri

I'm on the purpose that you to create a class that extends phalcon DI.

In it you redefine the get method ; add the _isresolved propertie ; and a isResolved Method:

// make your class
// Class MyDi extend Phalcon\DI...

protected $_resolvedList;

public functoin __construct(){
       $_resolvedList = array();

public function get($name,$parameters=array()){
     $this->_resolvedList[$name] = true;
    return parrent::get($name,$parameters);

// according to the doc there is also getRaw, getService, getShared they may need to be redefined (need to check the sources to know if they need to be redefined)

public function isResolved($name){
     return isset( $this->_resolvedList[$name] ) &&  $this->_resolvedList[$name] === true;

Then you can use it :

$di = new MyDi(); // intead of $di = new Phalcon\Di;

Doc :


Thanks, that's an obvious solution. However, that adds a complexity of supplying your own DI object into all DI instantiations.

What I'd like to do is to simply fetch that information from default DI container.


Phalcon shouldn't solve all your problem. It is framework to write your own app.


If you can, you should extend DI (I do this in every app) and maybe create pull request in phalcon/incubator. That way people who need it will benefit from your work and people who don't want, will be happy you didn't slow down framework.



I agree that Phalcon should not solve developer's specific problems, however, IMO, this should be available on system/extension level as fundamental functionality.