src/Injector.php
public function instantiate(string $class, array $parameters = [])
    {
        $class = new \ReflectionClass($class);
        $instance = $class->newInstanceWithoutConstructor();

        $this->inject($instance);

        $constructor = $class->getConstructor();

        if ($constructor) {
            $parameters = $this->getFunctionParameters($constructor, $parameters);
            $constructor->setAccessible(true);
            $constructor->invokeArgs($instance, $parameters);
        }

        return $instance;
    }
public function instantiate(string $class, array $parameters = [])
    {
        $class = new \ReflectionClass($class);
        $instance = $class->newInstanceWithoutConstructor();

        $this->inject($instance);

        $constructor = $class->getConstructor();

        if ($constructor) {
            $parameters = $this->getFunctionParameters($constructor, $parameters);
            $constructor->setAccessible(true);
            $constructor->invokeArgs($instance, $parameters);
        }

        return $instance;
    }
public function instantiate ( string $ class , array $ parameters = [ ] ) { $ class = new \ ReflectionClass ( $ class ) ; $ instance = $ class -> newInstanceWithoutConstructor ( ) ; $ this -> inject ( $ instance ) ; $ constructor = $ class -> getConstructor ( ) ; if ( $ constructor ) { $ parameters = $ this -> getFunctionParameters ( $ constructor , $ parameters ) ; $ constructor -> setAccessible ( true ) ; $ constructor -> invokeArgs ( $ instance , $ parameters ) ; } return $ instance ; }
Instantiates a class by resolving its constructor parameters, and injects dependencies in the resulting object.

If the given parameters match the constructor parameter names, the given values are used.
Otherwise, the constructor parameters are resolved using the ValueResolver.

@param string $class      The name of the class to instantiate.
@param array  $parameters An associative array of values for the constructor parameters.

@return object The instantiated object.

@throws UnresolvedValueException If a function parameter could not be resolved.
Instantiates a class by resolving its constructor parameters and injects dependencies in the resulting object .