src/Container.php
public function setTo(string $class, string $dependencyName, $dependency) : ContainerInterface
    {
        $key = "$class$dependencyName";

        if ($dependency instanceof Closure === false) {

            // let's use temporarily the set method to resolve
            // the $dependency if it is not a closure ready to use.

            $this->set($key, $dependency);
            $resolved = $this->collection[$key];

            // now we already have a resolved version of $dependency
            // we just need to ensure the dependencies type, a closure.

            $dependency = function () use ($resolved) {
                return $resolved;
            };

            // we have used the set method to resolve the $dependency
            // now that we have done all the process let's clear the memory.

            unset($resolved, $this->collection[$key]);
        }

        $this->dependencies[$key] = $dependency;

        return $this;
    }
public function setTo(string $class, string $dependencyName, $dependency) : ContainerInterface
    {
        $key = "$class$dependencyName";

        if ($dependency instanceof Closure === false) {

            // let's use temporarily the set method to resolve
            // the $dependency if it is not a closure ready to use.

            $this->set($key, $dependency);
            $resolved = $this->collection[$key];

            // now we already have a resolved version of $dependency
            // we just need to ensure the dependencies type, a closure.

            $dependency = function () use ($resolved) {
                return $resolved;
            };

            // we have used the set method to resolve the $dependency
            // now that we have done all the process let's clear the memory.

            unset($resolved, $this->collection[$key]);
        }

        $this->dependencies[$key] = $dependency;

        return $this;
    }
public function setTo ( string $ class , string $ dependencyName , $ dependency ) : ContainerInterface { $ key = "$class$dependencyName" ; if ( $ dependency instanceof Closure === false ) { // let's use temporarily the set method to resolve // the $dependency if it is not a closure ready to use. $ this -> set ( $ key , $ dependency ) ; $ resolved = $ this -> collection [ $ key ] ; // now we already have a resolved version of $dependency // we just need to ensure the dependencies type, a closure. $ dependency = function ( ) use ( $ resolved ) { return $ resolved ; } ; // we have used the set method to resolve the $dependency // now that we have done all the process let's clear the memory. unset ( $ resolved , $ this -> collection [ $ key ] ) ; } $ this -> dependencies [ $ key ] = $ dependency ; return $ this ; }
Bind an specific instance to a class dependency.

@param string         $class          The class full name.
@param string         $dependencyName The dependency full name.
@param string|closure $dependency     The specific object class name or a classure that makes the element.

@return ContainerInterface
Bind an specific instance to a class dependency .