public function newInstanceOf($class, array $arguments = [], bool $dependencyInjection = true)
    {
        try {
            // Reflection of class
            $reflectionClass = new \ReflectionClass($class);

            if (!is_null($constructor = $reflectionClass->getConstructor())) {
                // Dependency injection?
                if ($dependencyInjection) {
                    $arguments = $this->getDependencyInjectionParameters($constructor->getParameters(), $arguments);
                }
            }
        } catch (\Exception $e) {
            throw new InstantiatorException(sprintf('Error during dependency injection of class "%s"', $class), 0, $e);
        }

        if (is_null($constructor)) {
            return $reflectionClass->newInstanceWithoutConstructor();
        } else {
            return $reflectionClass->newInstanceArgs($arguments);
        }
    }
public function newInstanceOf($class, array $arguments = [], bool $dependencyInjection = true)
    {
        try {
            // Reflection of class
            $reflectionClass = new \ReflectionClass($class);

            if (!is_null($constructor = $reflectionClass->getConstructor())) {
                // Dependency injection?
                if ($dependencyInjection) {
                    $arguments = $this->getDependencyInjectionParameters($constructor->getParameters(), $arguments);
                }
            }
        } catch (\Exception $e) {
            throw new InstantiatorException(sprintf('Error during dependency injection of class "%s"', $class), 0, $e);
        }

        if (is_null($constructor)) {
            return $reflectionClass->newInstanceWithoutConstructor();
        } else {
            return $reflectionClass->newInstanceArgs($arguments);
        }
    }
public function newInstanceOf ( $ class , array $ arguments = [ ] , bool $ dependencyInjection = true ) { try { // Reflection of class $ reflectionClass = new \ ReflectionClass ( $ class ) ; if ( ! is_null ( $ constructor = $ reflectionClass -> getConstructor ( ) ) ) { // Dependency injection? if ( $ dependencyInjection ) { $ arguments = $ this -> getDependencyInjectionParameters ( $ constructor -> getParameters ( ) , $ arguments ) ; } } } catch ( \ Exception $ e ) { throw new InstantiatorException ( sprintf ( 'Error during dependency injection of class "%s"' , $ class ) , 0 , $ e ) ; } if ( is_null ( $ constructor ) ) { return $ reflectionClass -> newInstanceWithoutConstructor ( ) ; } else { return $ reflectionClass -> newInstanceArgs ( $ arguments ) ; } }
Create new instance of a class.

@param object|string $class               Class name or object
@param array         $arguments           Arguments
@param bool          $dependencyInjection Dependency injection? (default: true)

@return mixed
@throws \Berlioz\ServiceContainer\Exception\InstantiatorException
Create new instance of a class .