src/Core/DependencyInjector/DependencyInjector.php
public function prepare(&$instance)
    {
        $requirements = $this->getDiRequirements(get_class($instance));

        foreach ($requirements as $propertyName => $property) {

            $dependencyIdentifier = $property['identifier'];
            $dependency = $this->container[$dependencyIdentifier];

            if (!isset($this->container[$dependencyIdentifier])) {
                throw new \InvalidArgumentException("Unable to resolve dependency $dependencyIdentifier for injection");
            }

            if ($property['isPublic']) {
                // If its public, just set it!
                $instance->$propertyName = $dependency;
            } else {
                if ($property['setter']) {
                    // If there is a setter method, use that
                    call_user_func($instance, $property['setter'], $dependency);
                } else {
                    // Otherwise set by brute force
                    $refl = new \ReflectionClass($instance);
                    $prop = $refl->getProperty($propertyName);
                    $prop->setAccessible(true);
                    $prop->setValue($instance, $this->container[$dependencyIdentifier]);
                    $prop->setAccessible(false);
                }
            }

        }

    }
public function prepare(&$instance)
    {
        $requirements = $this->getDiRequirements(get_class($instance));

        foreach ($requirements as $propertyName => $property) {

            $dependencyIdentifier = $property['identifier'];
            $dependency = $this->container[$dependencyIdentifier];

            if (!isset($this->container[$dependencyIdentifier])) {
                throw new \InvalidArgumentException("Unable to resolve dependency $dependencyIdentifier for injection");
            }

            if ($property['isPublic']) {
                // If its public, just set it!
                $instance->$propertyName = $dependency;
            } else {
                if ($property['setter']) {
                    // If there is a setter method, use that
                    call_user_func($instance, $property['setter'], $dependency);
                } else {
                    // Otherwise set by brute force
                    $refl = new \ReflectionClass($instance);
                    $prop = $refl->getProperty($propertyName);
                    $prop->setAccessible(true);
                    $prop->setValue($instance, $this->container[$dependencyIdentifier]);
                    $prop->setAccessible(false);
                }
            }

        }

    }
public function prepare ( & $ instance ) { $ requirements = $ this -> getDiRequirements ( get_class ( $ instance ) ) ; foreach ( $ requirements as $ propertyName => $ property ) { $ dependencyIdentifier = $ property [ 'identifier' ] ; $ dependency = $ this -> container [ $ dependencyIdentifier ] ; if ( ! isset ( $ this -> container [ $ dependencyIdentifier ] ) ) { throw new \ InvalidArgumentException ( "Unable to resolve dependency $dependencyIdentifier for injection" ) ; } if ( $ property [ 'isPublic' ] ) { // If its public, just set it! $ instance -> $ propertyName = $ dependency ; } else { if ( $ property [ 'setter' ] ) { // If there is a setter method, use that call_user_func ( $ instance , $ property [ 'setter' ] , $ dependency ) ; } else { // Otherwise set by brute force $ refl = new \ ReflectionClass ( $ instance ) ; $ prop = $ refl -> getProperty ( $ propertyName ) ; $ prop -> setAccessible ( true ) ; $ prop -> setValue ( $ instance , $ this -> container [ $ dependencyIdentifier ] ) ; $ prop -> setAccessible ( false ) ; } } } }
Scan a class instance for injectable dependencies,
and inject them if found, then return prepared instance.

@param object $instance Class instance to prepare
@throws \RuntimeException
@throws \InvalidArgumentException
Scan a class instance for injectable dependencies and inject them if found then return prepared instance .