protected function construct(string $abstract) : Closure
    {
        $inspector = new ReflectionClass($abstract);

        if (($constructor = $inspector->getConstructor()) && ($dependencies = $constructor->getParameters())) {

            // if, and only if, a class has a constructor with parameters, we try to solve then
            // creating a resolving callback that in every call will recalculate all dependencies
            // for the given class, and offcourse, using a cached resolving callback if exists.

            return function (string $abstract, array $parameters) use ($inspector, $dependencies) {
                return $inspector->newInstanceArgs(
                    $this->process($abstract, $parameters, $dependencies)
                );
            };
        }

        return function (string $abstract) {
            return new $abstract;
        };
    }
protected function construct(string $abstract) : Closure
    {
        $inspector = new ReflectionClass($abstract);

        if (($constructor = $inspector->getConstructor()) && ($dependencies = $constructor->getParameters())) {

            // if, and only if, a class has a constructor with parameters, we try to solve then
            // creating a resolving callback that in every call will recalculate all dependencies
            // for the given class, and offcourse, using a cached resolving callback if exists.

            return function (string $abstract, array $parameters) use ($inspector, $dependencies) {
                return $inspector->newInstanceArgs(
                    $this->process($abstract, $parameters, $dependencies)
                );
            };
        }

        return function (string $abstract) {
            return new $abstract;
        };
    }
protected function construct ( string $ abstract ) : Closure { $ inspector = new ReflectionClass ( $ abstract ) ; if ( ( $ constructor = $ inspector -> getConstructor ( ) ) && ( $ dependencies = $ constructor -> getParameters ( ) ) ) { // if, and only if, a class has a constructor with parameters, we try to solve then // creating a resolving callback that in every call will recalculate all dependencies // for the given class, and offcourse, using a cached resolving callback if exists. return function ( string $ abstract , array $ parameters ) use ( $ inspector , $ dependencies ) { return $ inspector -> newInstanceArgs ( $ this -> process ( $ abstract , $ parameters , $ dependencies ) ) ; } ; } return function ( string $ abstract ) { return new $ abstract ; } ; }
Construct a class and all the dependencies using the reflection library of PHP.

@param string $abstract The class name or container element name to make.

@throws ReflectionException
@return Closure
Construct a class and all the dependencies using the reflection library of PHP .