public function resolveClass($name, $params = [])
    {
        $reflectionClass = new ReflectionClass($name);

        if (!$reflectionClass->isInstantiable()) {
            throw new Exception("The [ {$name} ] is not instantiable.");
        }

        $constructor = $reflectionClass->getConstructor();

        if (!is_null($constructor)) {
            $dependencies = $constructor->getParameters();

            $resolving = $this->getDependencies($dependencies, $params);

            $instance = $reflectionClass->newInstanceArgs($resolving);

            return $this->resolved[$name] = $this->getInstanceWithAppProperty($instance);
        }

        $instance = new $name;

        return $this->resolved[$name] = $this->getInstanceWithAppProperty($instance);
    }
public function resolveClass($name, $params = [])
    {
        $reflectionClass = new ReflectionClass($name);

        if (!$reflectionClass->isInstantiable()) {
            throw new Exception("The [ {$name} ] is not instantiable.");
        }

        $constructor = $reflectionClass->getConstructor();

        if (!is_null($constructor)) {
            $dependencies = $constructor->getParameters();

            $resolving = $this->getDependencies($dependencies, $params);

            $instance = $reflectionClass->newInstanceArgs($resolving);

            return $this->resolved[$name] = $this->getInstanceWithAppProperty($instance);
        }

        $instance = new $name;

        return $this->resolved[$name] = $this->getInstanceWithAppProperty($instance);
    }
public function resolveClass ( $ name , $ params = [ ] ) { $ reflectionClass = new ReflectionClass ( $ name ) ; if ( ! $ reflectionClass -> isInstantiable ( ) ) { throw new Exception ( "The [ {$name} ] is not instantiable." ) ; } $ constructor = $ reflectionClass -> getConstructor ( ) ; if ( ! is_null ( $ constructor ) ) { $ dependencies = $ constructor -> getParameters ( ) ; $ resolving = $ this -> getDependencies ( $ dependencies , $ params ) ; $ instance = $ reflectionClass -> newInstanceArgs ( $ resolving ) ; return $ this -> resolved [ $ name ] = $ this -> getInstanceWithAppProperty ( $ instance ) ; } $ instance = new $ name ; return $ this -> resolved [ $ name ] = $ this -> getInstanceWithAppProperty ( $ instance ) ; }
Resolve dependencies for a class.

@param string $name
@param array $params

@return object
@throws Exception
Resolve dependencies for a class .