Skip to content
This repository was archived by the owner on Jan 16, 2019. It is now read-only.

Implicit bindings

Frank Kleine edited this page Aug 3, 2014 · 4 revisions

Implicit bindings

Stubbles 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 will implicitly bind the concrete class to itself:

class Window {}

class BMW implements Car {
    protected $driver;
    protected $engine;
    protected $tire;
    protected $window;

    // same constructor and methods as in previous examples

    /**
     * @Inject
     */
    public function setWindow(Window $win) {
        $this->window = $win;
    }
}

When creating an instance of BMW, it will automatically have a reference to an instance of Window although no special binding has been added.

Please note that implicit bindings turn into explicit bindings once one of these methods is called:

  • stubbles\ioc\Binder::hasBinding()
  • stubbles\ioc\Injector::hasBinding()
  • stubbles\ioc\Injector::getInstance()
Clone this wiki locally