public function resolveClass(string $class, array $parameters = []): object
    {
        $reflectionClass = new ReflectionClass($class);

        if (! $reflectionClass->isInstantiable()) {
            throw new BindingResolutionException(
                \sprintf(
                    'Unable to reflect on the class [%s], does the class exist and is it properly autoloaded?',
                    $class
                )
            );
        }

        if (\in_array($class, $this->buildStack, true)) {
            $this->buildStack[] = $class;

            throw new CyclicDependencyException($class, $this->buildStack);
        }

        $reflectionMethod   = $reflectionClass->getConstructor();
        $this->buildStack[] = $reflectionClass->name;

        if ($reflectionMethod) {
            $reflectionParameters = $reflectionMethod->getParameters();
            $parameters           = $this->resolveParameters($reflectionParameters, $parameters);
        }

        \array_pop($this->buildStack);

        return $reflectionClass->newInstanceArgs($parameters);
    }
public function resolveClass(string $class, array $parameters = []): object
    {
        $reflectionClass = new ReflectionClass($class);

        if (! $reflectionClass->isInstantiable()) {
            throw new BindingResolutionException(
                \sprintf(
                    'Unable to reflect on the class [%s], does the class exist and is it properly autoloaded?',
                    $class
                )
            );
        }

        if (\in_array($class, $this->buildStack, true)) {
            $this->buildStack[] = $class;

            throw new CyclicDependencyException($class, $this->buildStack);
        }

        $reflectionMethod   = $reflectionClass->getConstructor();
        $this->buildStack[] = $reflectionClass->name;

        if ($reflectionMethod) {
            $reflectionParameters = $reflectionMethod->getParameters();
            $parameters           = $this->resolveParameters($reflectionParameters, $parameters);
        }

        \array_pop($this->buildStack);

        return $reflectionClass->newInstanceArgs($parameters);
    }
public function resolveClass ( string $ class , array $ parameters = [ ] ) : object { $ reflectionClass = new ReflectionClass ( $ class ) ; if ( ! $ reflectionClass -> isInstantiable ( ) ) { throw new BindingResolutionException ( \ sprintf ( 'Unable to reflect on the class [%s], does the class exist and is it properly autoloaded?' , $ class ) ) ; } if ( \ in_array ( $ class , $ this -> buildStack , true ) ) { $ this -> buildStack [ ] = $ class ; throw new CyclicDependencyException ( $ class , $ this -> buildStack ) ; } $ reflectionMethod = $ reflectionClass -> getConstructor ( ) ; $ this -> buildStack [ ] = $ reflectionClass -> name ; if ( $ reflectionMethod ) { $ reflectionParameters = $ reflectionMethod -> getParameters ( ) ; $ parameters = $ this -> resolveParameters ( $ reflectionParameters , $ parameters ) ; } \ array_pop ( $ this -> buildStack ) ; return $ reflectionClass -> newInstanceArgs ( $ parameters ) ; }
Resolve a class.

@param string $class
@param array  $parameters

@throws \Viserio\Component\Contract\Container\Exception\BindingResolutionException
@throws \Viserio\Component\Contract\Container\Exception\CyclicDependencyException
@throws \ReflectionException

@return object
Resolve a class .