protected function resolveClass(string $class, array $primitives = [])
    {
        try {
            if (isset($this->constructorReflectionCache[$class])) {
                list($constructor, $parameters) = $this->constructorReflectionCache[$class];
            } else {
                $reflectionClass = new ReflectionClass($class);
                if (!$reflectionClass->isInstantiable()) {
                    throw new IocException(
                        sprintf(
                            '%s is not instantiable%s',
                            $class,
                            $this->currentTarget === null ? '' : " (dependency of {$this->currentTarget})"
                        )
                    );
                }

                $constructor = $reflectionClass->getConstructor();
                $parameters = $constructor !== null ? $constructor->getParameters() : null;
                $this->constructorReflectionCache[$class] = [$constructor, $parameters];
            }

            if ($constructor === null) {
                // No constructor, so instantiating is easy
                return new $class;
            }

            $constructorParameters = $this->resolveParameters($class, $parameters, $primitives);

            return new $class(...$constructorParameters);
        } catch (ReflectionException $ex) {
            throw new IocException("Failed to resolve class $class", 0, $ex);
        }
    }
protected function resolveClass(string $class, array $primitives = [])
    {
        try {
            if (isset($this->constructorReflectionCache[$class])) {
                list($constructor, $parameters) = $this->constructorReflectionCache[$class];
            } else {
                $reflectionClass = new ReflectionClass($class);
                if (!$reflectionClass->isInstantiable()) {
                    throw new IocException(
                        sprintf(
                            '%s is not instantiable%s',
                            $class,
                            $this->currentTarget === null ? '' : " (dependency of {$this->currentTarget})"
                        )
                    );
                }

                $constructor = $reflectionClass->getConstructor();
                $parameters = $constructor !== null ? $constructor->getParameters() : null;
                $this->constructorReflectionCache[$class] = [$constructor, $parameters];
            }

            if ($constructor === null) {
                // No constructor, so instantiating is easy
                return new $class;
            }

            $constructorParameters = $this->resolveParameters($class, $parameters, $primitives);

            return new $class(...$constructorParameters);
        } catch (ReflectionException $ex) {
            throw new IocException("Failed to resolve class $class", 0, $ex);
        }
    }
protected function resolveClass ( string $ class , array $ primitives = [ ] ) { try { if ( isset ( $ this -> constructorReflectionCache [ $ class ] ) ) { list ( $ constructor , $ parameters ) = $ this -> constructorReflectionCache [ $ class ] ; } else { $ reflectionClass = new ReflectionClass ( $ class ) ; if ( ! $ reflectionClass -> isInstantiable ( ) ) { throw new IocException ( sprintf ( '%s is not instantiable%s' , $ class , $ this -> currentTarget === null ? '' : " (dependency of {$this->currentTarget})" ) ) ; } $ constructor = $ reflectionClass -> getConstructor ( ) ; $ parameters = $ constructor !== null ? $ constructor -> getParameters ( ) : null ; $ this -> constructorReflectionCache [ $ class ] = [ $ constructor , $ parameters ] ; } if ( $ constructor === null ) { // No constructor, so instantiating is easy return new $ class ; } $ constructorParameters = $ this -> resolveParameters ( $ class , $ parameters , $ primitives ) ; return new $ class ( ... $ constructorParameters ) ; } catch ( ReflectionException $ ex ) { throw new IocException ( "Failed to resolve class $class" , 0 , $ ex ) ; } }
Resolves a class

@param string $class The class name to resolve
@param array $primitives The list of constructor primitives
@return object The resolved class
@throws IocException Thrown if the class could not be resolved
Resolves a class