protected function build($class, $config)
    {	
        /* @var $reflection ReflectionClass */
        list ($reflection, $dependencies) = $this->getDependencies($class);
        
        $dependencies = $this->resolveDependencies($dependencies, $reflection);
        
        if (empty($config)) {
            return $reflection->newInstanceArgs($dependencies);
        }
        
        if (!empty($dependencies) && $reflection->implementsInterface('Wslim\Common\ConfigurableInterface')) {
            
            // set $config as the last parameter (existing one will be overwritten)
            $dependencies[count($dependencies) - 1] = $config;
            
            return $reflection->newInstanceArgs($dependencies);
        } else {
            $object = $reflection->newInstanceArgs($dependencies);
            foreach ($config as $name => $value) {
                $method = 'set' . ucfirst($name);
                if (method_exists($object, $method)) {
                    $object->$method($value);
                } else {
                    $object->$name = $value;
                }
            }
            
            return $object;
        }
    }
protected function build($class, $config)
    {	
        /* @var $reflection ReflectionClass */
        list ($reflection, $dependencies) = $this->getDependencies($class);
        
        $dependencies = $this->resolveDependencies($dependencies, $reflection);
        
        if (empty($config)) {
            return $reflection->newInstanceArgs($dependencies);
        }
        
        if (!empty($dependencies) && $reflection->implementsInterface('Wslim\Common\ConfigurableInterface')) {
            
            // set $config as the last parameter (existing one will be overwritten)
            $dependencies[count($dependencies) - 1] = $config;
            
            return $reflection->newInstanceArgs($dependencies);
        } else {
            $object = $reflection->newInstanceArgs($dependencies);
            foreach ($config as $name => $value) {
                $method = 'set' . ucfirst($name);
                if (method_exists($object, $method)) {
                    $object->$method($value);
                } else {
                    $object->$name = $value;
                }
            }
            
            return $object;
        }
    }
protected function build ( $ class , $ config ) { /* @var $reflection ReflectionClass */ list ( $ reflection , $ dependencies ) = $ this -> getDependencies ( $ class ) ; $ dependencies = $ this -> resolveDependencies ( $ dependencies , $ reflection ) ; if ( empty ( $ config ) ) { return $ reflection -> newInstanceArgs ( $ dependencies ) ; } if ( ! empty ( $ dependencies ) && $ reflection -> implementsInterface ( 'Wslim\Common\ConfigurableInterface' ) ) { // set $config as the last parameter (existing one will be overwritten) $ dependencies [ count ( $ dependencies ) - 1 ] = $ config ; return $ reflection -> newInstanceArgs ( $ dependencies ) ; } else { $ object = $ reflection -> newInstanceArgs ( $ dependencies ) ; foreach ( $ config as $ name => $ value ) { $ method = 'set' . ucfirst ( $ name ) ; if ( method_exists ( $ object , $ method ) ) { $ object -> $ method ( $ value ) ; } else { $ object -> $ name = $ value ; } } return $ object ; } }
Creates an instance of the specified class.
This method will resolve dependencies of the specified class, instantiate them, and inject
them into the new instance of the specified class.
@param  string $class the class name
@param  array  $config constructor parameters
@return object the newly created instance of the specified class
Creates an instance of the specified class . This method will resolve dependencies of the specified class instantiate them and inject them into the new instance of the specified class .