lib/Context.php
public function registerInstance($object)
    {
        if (!is_object($object)) {
            throw new \InvalidArgumentException('registerInstance(): Cannot pass primitive types, can only register an object instance; use registerVariable() instead');
        }

        $reflectionObject = new \ReflectionObject($object);
        $className = $reflectionObject->getName();

        // Register strong link in $instance
        $this->instances[$className] = $object;

        // Recursively determine and register weak links
        $determineParent = function (\ReflectionClass $class) use ($className, &$determineParent) {
            $parentClass = $class->getParentClass();

            if (!empty($parentClass)) {
                $this->weakLinks[$parentClass->getName()] = $className;
                $determineParent($parentClass);
            }
        };

        $determineParent($reflectionObject);
    }
public function registerInstance($object)
    {
        if (!is_object($object)) {
            throw new \InvalidArgumentException('registerInstance(): Cannot pass primitive types, can only register an object instance; use registerVariable() instead');
        }

        $reflectionObject = new \ReflectionObject($object);
        $className = $reflectionObject->getName();

        // Register strong link in $instance
        $this->instances[$className] = $object;

        // Recursively determine and register weak links
        $determineParent = function (\ReflectionClass $class) use ($className, &$determineParent) {
            $parentClass = $class->getParentClass();

            if (!empty($parentClass)) {
                $this->weakLinks[$parentClass->getName()] = $className;
                $determineParent($parentClass);
            }
        };

        $determineParent($reflectionObject);
    }
public function registerInstance ( $ object ) { if ( ! is_object ( $ object ) ) { throw new \ InvalidArgumentException ( 'registerInstance(): Cannot pass primitive types, can only register an object instance; use registerVariable() instead' ) ; } $ reflectionObject = new \ ReflectionObject ( $ object ) ; $ className = $ reflectionObject -> getName ( ) ; // Register strong link in $instance $ this -> instances [ $ className ] = $ object ; // Recursively determine and register weak links $ determineParent = function ( \ ReflectionClass $ class ) use ( $ className , & $ determineParent ) { $ parentClass = $ class -> getParentClass ( ) ; if ( ! empty ( $ parentClass ) ) { $ this -> weakLinks [ $ parentClass -> getName ( ) ] = $ className ; $ determineParent ( $ parentClass ) ; } } ; $ determineParent ( $ reflectionObject ) ; }
Registers an object instance to the context.
If an instance with the same type is already registered, this will override it.

@param object $object
Registers an object instance to the context . If an instance with the same type is already registered this will override it .