private function buildInstance(\ReflectionClass $reflection)
    {
        if (($constructor = $reflection->getConstructor()) === null) {
            return $reflection->newInstance();
        }
        $constructorParameters = [];
        foreach ($constructor->getParameters() as $parameter) {
            if (($parameterClass = $parameter->getClass()) === null) {
                throw new ContainerException(sprintf(
                    'Class "%s" constructor has a scalar / callable / array type parameter',
                    $reflection->getName()
                ));
            }
            $constructorParameters[] = $this->get($parameterClass->getName());
        }
        return $reflection->newInstanceArgs($constructorParameters);
    }
private function buildInstance(\ReflectionClass $reflection)
    {
        if (($constructor = $reflection->getConstructor()) === null) {
            return $reflection->newInstance();
        }
        $constructorParameters = [];
        foreach ($constructor->getParameters() as $parameter) {
            if (($parameterClass = $parameter->getClass()) === null) {
                throw new ContainerException(sprintf(
                    'Class "%s" constructor has a scalar / callable / array type parameter',
                    $reflection->getName()
                ));
            }
            $constructorParameters[] = $this->get($parameterClass->getName());
        }
        return $reflection->newInstanceArgs($constructorParameters);
    }
private function buildInstance ( \ ReflectionClass $ reflection ) { if ( ( $ constructor = $ reflection -> getConstructor ( ) ) === null ) { return $ reflection -> newInstance ( ) ; } $ constructorParameters = [ ] ; foreach ( $ constructor -> getParameters ( ) as $ parameter ) { if ( ( $ parameterClass = $ parameter -> getClass ( ) ) === null ) { throw new ContainerException ( sprintf ( 'Class "%s" constructor has a scalar / callable / array type parameter' , $ reflection -> getName ( ) ) ) ; } $ constructorParameters [ ] = $ this -> get ( $ parameterClass -> getName ( ) ) ; } return $ reflection -> newInstanceArgs ( $ constructorParameters ) ; }
Build a new instance of a class from reflection class and auto-resolved constructor arguments.

@param \ReflectionClass $reflection The reflection class.

@return mixed The built instance.

@throws ContainerException If the class constructor is not public.
Build a new instance of a class from reflection class and auto - resolved constructor arguments .