public function injectDependencies(DescriptorInterface $objectDescriptor, $instance)
    {

        // try to load the reflection class
        $reflectionClass = $this->getReflectionClass($objectDescriptor->getClassName());

        // load the dependencies for the passed descriptor
        $dependencies = $this->loadDependencies($objectDescriptor);

        // iterate over all methods and inject the dependencies
        foreach ($dependencies['method'] as $methodName => $toInject) {
            // query whether or not the method exists
            if ($reflectionClass->hasMethod($methodName)) {
                // inject the target by invoking the method
                call_user_func_array(array($instance, $methodName), $toInject);
            }
        }

        // inject dependencies by property
        foreach ($dependencies['property'] as $propertyName => $toInject) {
            // query whether or not the property exists
            if ($reflectionClass->hasProperty($propertyName)) {
                // load the reflection property
                $reflectionProperty = $reflectionClass->getProperty($propertyName);

                // load the PHP ReflectionProperty instance to inject the bean instance
                $phpReflectionProperty = $reflectionProperty->toPhpReflectionProperty();
                $phpReflectionProperty->setAccessible(true);
                $phpReflectionProperty->setValue($instance, $toInject);
            }
        }
    }
public function injectDependencies(DescriptorInterface $objectDescriptor, $instance)
    {

        // try to load the reflection class
        $reflectionClass = $this->getReflectionClass($objectDescriptor->getClassName());

        // load the dependencies for the passed descriptor
        $dependencies = $this->loadDependencies($objectDescriptor);

        // iterate over all methods and inject the dependencies
        foreach ($dependencies['method'] as $methodName => $toInject) {
            // query whether or not the method exists
            if ($reflectionClass->hasMethod($methodName)) {
                // inject the target by invoking the method
                call_user_func_array(array($instance, $methodName), $toInject);
            }
        }

        // inject dependencies by property
        foreach ($dependencies['property'] as $propertyName => $toInject) {
            // query whether or not the property exists
            if ($reflectionClass->hasProperty($propertyName)) {
                // load the reflection property
                $reflectionProperty = $reflectionClass->getProperty($propertyName);

                // load the PHP ReflectionProperty instance to inject the bean instance
                $phpReflectionProperty = $reflectionProperty->toPhpReflectionProperty();
                $phpReflectionProperty->setAccessible(true);
                $phpReflectionProperty->setValue($instance, $toInject);
            }
        }
    }
public function injectDependencies ( DescriptorInterface $ objectDescriptor , $ instance ) { // try to load the reflection class $ reflectionClass = $ this -> getReflectionClass ( $ objectDescriptor -> getClassName ( ) ) ; // load the dependencies for the passed descriptor $ dependencies = $ this -> loadDependencies ( $ objectDescriptor ) ; // iterate over all methods and inject the dependencies foreach ( $ dependencies [ 'method' ] as $ methodName => $ toInject ) { // query whether or not the method exists if ( $ reflectionClass -> hasMethod ( $ methodName ) ) { // inject the target by invoking the method call_user_func_array ( array ( $ instance , $ methodName ) , $ toInject ) ; } } // inject dependencies by property foreach ( $ dependencies [ 'property' ] as $ propertyName => $ toInject ) { // query whether or not the property exists if ( $ reflectionClass -> hasProperty ( $ propertyName ) ) { // load the reflection property $ reflectionProperty = $ reflectionClass -> getProperty ( $ propertyName ) ; // load the PHP ReflectionProperty instance to inject the bean instance $ phpReflectionProperty = $ reflectionProperty -> toPhpReflectionProperty ( ) ; $ phpReflectionProperty -> setAccessible ( true ) ; $ phpReflectionProperty -> setValue ( $ instance , $ toInject ) ; } } }
Injects the dependencies of the passed instance defined in the object descriptor.


@param \AppserverIo\Psr\Deployment\DescriptorInterface $objectDescriptor The object descriptor with the dependencies
@param object                                          $instance         The instance to inject the dependencies for

@return void
Injects the dependencies of the passed instance defined in the object descriptor .