public function create($className, $parameters = [])
    {
        $reflectionClass = new \ReflectionClass($className);
        if (!$reflectionClass->hasMethod("__construct")) {
            //This class doesn't have a constructor
            return $reflectionClass->newInstanceWithoutConstructor();
        }
        if (!$reflectionClass->getMethod('__construct')->isPublic()) {
            throw new InjectorInvocationException(
                "Injector failed to create $className - constructor isn't public." .
                " Do you need to use a static factory method instead?"
            );
        }
        try {
            $parameters = $this->buildParameterArray(
                $this->inspector->getSignatureByReflectionClass($reflectionClass, "__construct"),
                $parameters
            );

            return $reflectionClass->newInstanceArgs($parameters);
        } catch (MissingRequiredParameterException $e) {
            throw new InjectorInvocationException(
                "Can't create $className " .
                " - __construct() missing parameter '" . $e->getParameterString() . "'" .
                " could not be found. Either register it as a service or pass it to create via parameters."
            );
        } catch (InjectorInvocationException $e) {
            //Wrap the exception stack for recursive calls to aid debugging
            throw new InjectorInvocationException(
                $e->getMessage() .
                PHP_EOL . " => (Called when creating $className)"
            );
        }
    }
public function create($className, $parameters = [])
    {
        $reflectionClass = new \ReflectionClass($className);
        if (!$reflectionClass->hasMethod("__construct")) {
            //This class doesn't have a constructor
            return $reflectionClass->newInstanceWithoutConstructor();
        }
        if (!$reflectionClass->getMethod('__construct')->isPublic()) {
            throw new InjectorInvocationException(
                "Injector failed to create $className - constructor isn't public." .
                " Do you need to use a static factory method instead?"
            );
        }
        try {
            $parameters = $this->buildParameterArray(
                $this->inspector->getSignatureByReflectionClass($reflectionClass, "__construct"),
                $parameters
            );

            return $reflectionClass->newInstanceArgs($parameters);
        } catch (MissingRequiredParameterException $e) {
            throw new InjectorInvocationException(
                "Can't create $className " .
                " - __construct() missing parameter '" . $e->getParameterString() . "'" .
                " could not be found. Either register it as a service or pass it to create via parameters."
            );
        } catch (InjectorInvocationException $e) {
            //Wrap the exception stack for recursive calls to aid debugging
            throw new InjectorInvocationException(
                $e->getMessage() .
                PHP_EOL . " => (Called when creating $className)"
            );
        }
    }
public function create ( $ className , $ parameters = [ ] ) { $ reflectionClass = new \ ReflectionClass ( $ className ) ; if ( ! $ reflectionClass -> hasMethod ( "__construct" ) ) { //This class doesn't have a constructor return $ reflectionClass -> newInstanceWithoutConstructor ( ) ; } if ( ! $ reflectionClass -> getMethod ( '__construct' ) -> isPublic ( ) ) { throw new InjectorInvocationException ( "Injector failed to create $className - constructor isn't public." . " Do you need to use a static factory method instead?" ) ; } try { $ parameters = $ this -> buildParameterArray ( $ this -> inspector -> getSignatureByReflectionClass ( $ reflectionClass , "__construct" ) , $ parameters ) ; return $ reflectionClass -> newInstanceArgs ( $ parameters ) ; } catch ( MissingRequiredParameterException $ e ) { throw new InjectorInvocationException ( "Can't create $className " . " - __construct() missing parameter '" . $ e -> getParameterString ( ) . "'" . " could not be found. Either register it as a service or pass it to create via parameters." ) ; } catch ( InjectorInvocationException $ e ) { //Wrap the exception stack for recursive calls to aid debugging throw new InjectorInvocationException ( $ e -> getMessage ( ) . PHP_EOL . " => (Called when creating $className)" ) ; } }
Instantiate an object and attempt to inject the dependencies for the class by mapping constructor parameter \
names to objects registered within the IoC container.

The optional $parameters passed to this method accept and will inject values based on:
- Type:  [Cache::class => new RedisCache()] will inject RedisCache to each parameter typed Cache::class
- Name:  ["cache" => new RedisCache()] will inject RedisCache to the parameter named $cache
- Index: [ 3 => new RedisCache()] will inject RedisCache to the 4th parameter (zero index)

@param string $className The fully qualified class name for the object we're creating
@param array $parameters An optional array of additional parameters to pass to the created objects constructor.
@return object
@throws InjectorInvocationException
@throws \InvalidArgumentException
@throws \ReflectionException
Instantiate an object and attempt to inject the dependencies for the class by mapping constructor parameter \ names to objects registered within the IoC container .