Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 897 Bytes

File metadata and controls

29 lines (22 loc) · 897 Bytes

Implicit bindings

stubbles/ioc does not force you to use interfaces in your type hints. If you are already using concrete classes, there is no need to bind them, as stubbles/ioc will implicitly bind the concrete class to itself:

class Window {}

class House {
    private $window;

    public function __construct(Window $window) {
        $this->window = $window;
    }
}

When creating an instance of House, it will automatically have a reference to an instance of Window although no special binding has been added. This also works when Window itself has dependencies to other classes or constants.

Please note that implicit bindings turn into explicit bindings once and injection takes place or one of these methods is called:

  • stubbles\ioc\Binder::hasBinding()
  • stubbles\ioc\Injector::hasBinding()
  • stubbles\ioc\Injector::getInstance()