Instantiates a Module or ModuleGenerator instance.

@param string $class
@return ModuleInterface|ModuleGeneratorInterface
352378
protected function instantiateClass($class)
    {
        try {
            $instance = app($class);

        } catch (BindingResolutionException $e) {

            throw new InvalidArgumentException(
                "Failed to instantiate Module or ModuleGenerator instance for '{$class}'",
                $e->getCode(),
                $e
            );

        } catch (ReflectionException $e) {

            throw new InvalidArgumentException(
                "Failed to instantiate Module or ModuleGenerator instance for '{$class}'",
                $e->getCode(),
                $e
            );
        }

        if (    ! ($instance instanceof ModuleInterface)
            &&  ! ($instance instanceof ModuleGeneratorInterface)
        ) {
            throw new InvalidArgumentException(
                "Expected ModuleInterface or ModuleGeneratorInterface, got '{$class}'"
            );
        }

        return $instance;
    }
141023
public function getNewInstance($class) {
		if (isset($this->aliases[$class])) {
			$class = $this->aliases[$class];
		}

		$args = $this->resolveArgs($class, '__construct', " when constructing $class");
		if ($args) {
			$instance = new $class(...$args);
		} else {
			$instance = new $class;
		}

		return $instance;
	}
940143
public function on($class)
    {
        $this->instance = is_string($class) ? $this->container !== null ? $this->container->make($class) : new $class : $class;
        
        return $this;
    }
904158
public function getClass(string $class){
        if(!class_exists($class)){
            throw new \InvalidArgumentException();
        }

        if(!array_key_exists($class, $this->classes)){
            $this->classes[$class]  = new \ReflectionClass($class);
        }

        return $this->classes[$class];
    }
400505
public function newInstance($class = null, $options = [])
    {
        if ($class === null) {
            $class = get_class($this);
        } elseif ($class instanceof self) {
            $class = get_class($class);
        }

        if (is_string($class) && $class[0] != '\\') {
            $class = '\\'.$class;
        }

        if ($this->persistence) {
            return $this->persistence->add($class, $options);
        }

        return new $class($options);
    }
965376
public function factory($class, array $parameters = []): object
	{
		// Instantiate class

		if($class instanceof Closure)
		{
			$instance = $this->closureFactory($class, $parameters);
		}
		else
		{
			$instance = $this->reflectionFactory($class, $parameters);
		}

		// Inject container using setter if the class is container aware

		if($this->isContainerAware($instance))
		{
			$instance->setContainer($this);
		}

		// Return the instance

		return $instance;
	}
541386
public function create(string $class) : BootstrapperInterface
    {
        if (!isset($this->instances[$class])) {
            $this->instances[$class] = new $class($this->container, $this->bootstrappers->getPaths());
        }

        return $this->instances[$class];
    }
570979
protected function getFactory($class) {
		if (isset($this->factories[$class])) {
			return $this->factories[$class];
		}

		$factory = new $class($this);
		$this->factories[$class] = $factory;
		return $factory;
	}
282574
public static function create($class)
    {
        try {
            $reflection = new \ReflectionClass($class);
        } catch (\ReflectionException $e) {
            return false;
        }

        $constructor = $reflection->getConstructor();

        // If there are no parameters, just return a new object.
        if (null === $constructor) {
            return new $class;
        }

        $newInstanceArgs = self::getMethodArgs($constructor);

        // Create a callable for the dataStorage
        return $reflection->newInstanceArgs($newInstanceArgs);
    }
1343788
private function createInstance(string $class, array $parameters, string $context = null)
    {
        $reflection = new \ReflectionClass($class);

        //We have to construct class using external injector when we know exact context
        if (empty($parameters) && $this->hasInjector($reflection)) {
            $instance = $this->getInjector($reflection)->createInjection($reflection, $context);

            if (!$reflection->isInstance($instance)) {
                throw new InjectionException("Invalid injection response for '{$reflection->getName()}'");
            }

            return $instance;
        }

        if (!$reflection->isInstantiable()) {
            throw new ContainerException("Class '{$class}' can not be constructed");
        }

        if (!empty($constructor = $reflection->getConstructor())) {
            //Using constructor with resolved arguments
            $instance = $reflection->newInstanceArgs(
                $this->resolveArguments($constructor, $parameters)
            );
        } else {
            //No constructor specified
            $instance = $reflection->newInstance();
        }

        return $instance;
    }
730373
public static function buildClass( $class, array $parameters = [] )
	{
		if ( !is_string( $class ) )
			throw new BindingException( "Class must be a string" );

		if ( static::building( $class ) )
			throw new BindingException( "The class [" . $class . "] is already being built." );

		static::$buildStack[] = $class;

		try
		{
			$reflector = new \ReflectionClass( $class );

			// If the type is not instantiable, the developer is attempting to resolve
			// an abstract type such as an Interface of Abstract Class and there is
			// no binding registered for the abstractions so we need to bail out.
			if ( !$reflector->isInstantiable() )
				throw new BindingException( "Target [$class] is not instantiable." );

			$constructor = $reflector->getConstructor();

			// If there are no constructors, that means there are no dependencies then
			// we can just resolve the instances of the objects right away.
			if ( is_null( $constructor ) )
				return new $class;

			$dependencies = $constructor->getParameters();

			// Once we have all the constructor's parameters we can create each of the
			// dependency instances and then use the reflection instances to make a
			// new instance of this class, injecting the created dependencies in.
			$parameters = static::keyParametersByArgument( $dependencies, $parameters );

			$instances = static::getDependencies( $dependencies, $parameters, $class );

			array_pop( static::$buildStack );

			/**/

			return $reflector->newInstanceArgs( $instances );
		}
		catch ( \ReflectionException $e )
		{
			array_pop( static::$buildStack );

			throw new BindingException( "Failed to build [$class]: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() );
		}
	}
81955
public function add($class = null)
        {
            $class = $this->getClass($class);

            if (!Arrays::exists($class, $this->reflections)) {
                $this->reflections[$class] = new ReflectionClass($class);
            }

            return $this;
        }
238077
public function create($class, array $arguments = [])
    {
        $instanceType = $this->getInstanceType($class);
        $instanceArguments = $this->getInstanceArguments($class, $arguments);
        $reflection = new \ReflectionClass($instanceType);
        $constructor = $reflection->getConstructor();

        if (null === $constructor) {
            $instance = new $instanceType();
        } else {
            $args = $this->resolveArguments($constructor, $instanceArguments);
            $instance = $reflection->newInstanceArgs($args);
        }

        return $instance;
    }
113412
public function createInstance(string $class)
    {
        $reflection = new \ReflectionClass($class);

        // If the constructor has no parameters, there is no need to resolve them
        $constructor = $reflection->getConstructor();
        if (is_null($constructor)) {
            $this->instances[$class] = new $class;

            return new $class;
        }

        // Resolve the dependencies recursively
        $dependencies = $constructor->getParameters();
        $instances = $this->resolveDependencies($dependencies);

        $o = $reflection->newInstanceArgs($instances);
        $this->instances[$class] = $o;

        return $o;
    }
571168
private function newInstance($class)
    {
        $entity = $class->newInstance();

        if ($entity instanceof \Doctrine\Common\Persistence\ObjectManagerAware) {
            $entity->injectObjectManager($this->em, $class);
        }

        return $entity;
    }
790922
private function getService(string $class): ServiceInterface
    {
        if (!array_key_exists($class, $this->services)) {
            $this->services[$class] = new $class($this->client, $this->modelFactory);
        }

        return $this->services[$class];
    }
17923
protected function makeModelInstance($class)
    {
        if ( ! class_exists($class)) {
            throw new UnexpectedValueException("Class '{$class}' does not exist");
        }

        $instance = new $class;

        if ( ! $instance instanceof Model) {
            throw new UnexpectedValueException("Instance of '{$class}' is not a model");
        }

        $this->modelInstance = $instance;

        $this->modelReflection = new ReflectionClass($class);

        return $this;
    }