Construct an instance of the given class using the given arguments.

@param string $clazz Class name
@param array $args Constructor arguments
@return mixed Constructed instance
772191
public static function constructClassInstance( $clazz, $args ) {
		// $args should be a non-associative array; show nice error if that's not the case
		if ( $args && array_keys( $args ) !== range( 0, count( $args ) - 1 ) ) {
			throw new InvalidArgumentException( __METHOD__ . ': $args cannot be an associative array' );
		}

		return new $clazz( ...$args );
	}
93361
public function make($classname, ...$args)
    {
        $resource = $this->resolve($classname);
        return $resource->make(...$args);
    }
357057
public static function getInstance(...$args)
    {
        if(static::isChildClassSingleton())
        {
            $className = static::class;
            if(!isset(static::$instances[$className]))
            {
                static::$instances[$className] = new static(...$args);
            }
            return static::$instances[$className];
        }
        else
        {
            if(null === static::$instance)
            {
                static::$instance = new static(...$args);
            }
            return static::$instance;
        }
    }
707837
private static Object newInstance(Class<?> clazz) {
        Object instance = null;
        try {
            instance = clazz.newInstance();
        } catch (Exception ex) {
            log.error("Error loading class: {}", clazz.getName(), ex);
        }
        return instance;
    }
613321
public function build($class, ...$arguments)
    {
        if (is_object($class)) {
            return $class;
        }

        if (!class_exists($class)) {
            throw new InvalidArgumentException("Unable to build class: $class it does not exist");
        }

        $reflection = new ReflectionClass($class);
        $this->log(LogLevel::DEBUG, "Building class: {class}", ['class' => $class]);
        $object = $reflection->newInstanceArgs($arguments);

        if ($object instanceof BuilderAwareInterface) {
            $object->setBuilder($this);
        }

        if ($this->logger && ($object instanceof LoggerAwareInterface)) {
            $object->setLogger($this->logger);
        }

        return $object;
    }
1050661
public static function cli($args)
    {
        $cwd = getcwd();
        $cli = new self($cwd);

        return $cli->run(array_slice($args, 1));
    }
572877
public function create($definition, array $args = array())
    {
        $className = $definition;

        if(is_array($definition))
        {
            $className = $definition['class'];

            if(isset($definition['arguments']))
                $args = array_merge($args, $definition['arguments']);
        }
        else
        {
            $className = $definition;
        }

        $className = $this->buildClassName($className);

        // class name does not exists in the given path.
        if(!class_exists($className))
            throw new \Exedra\Exception\NotFoundException('Class named ['.$className.'] does not exists.');

        if(count($args))
        {
            $reflection	= new \ReflectionClass($className);

            $instance	= $reflection->newInstanceArgs($args);
        }
        else
        {
            $instance	= new $className;
        }

        return $instance;
    }
826127
public function build($args)
    {
        $data = [];

        $args = Cuztom::merge($args, [
            'parent'   => $this,
            'metaType' => $this->metaType,
            'object'   => $this->object,
        ]);

        // Build with value
        if (Cuztom::isArray($this->value)) {
            $i = 0;

            foreach ($this->value as $value) {
                $args = Cuztom::merge($args, "index=>$i");

                $data[] = new BundleItem($args, $value);

                $i++;
            }
        }

        // Without value
        else {
            $args = Cuztom::merge($args, 'index=>0');

            $data[] = new BundleItem($args);
        }

        return $data;
    }
135148
public function get($class, ...$args)
    {
        $poolName = trim($class, '\\');

        if (!$poolName) {
            return null;
        }

        $pool     = $this->map[$poolName] ?? null;
        if ($pool == null) {
            $pool = $this->applyNewPool($poolName);
        }

        if ($pool->count()) {
            $obj = $pool->shift();
            $obj->__isConstruct = false;
            return $obj;
        } else {
            $reflector         = new \ReflectionClass($poolName);
            $obj               = $reflector->newInstanceWithoutConstructor();
            $obj->__useCount   = 0;
            $obj->__genTime    = time();
            $obj->__isConstruct = false;
            $obj->__DSLevel    = Macro::DS_PUBLIC;
            unset($reflector);
            return $obj;
        }
    }
39590
public static function init ($name = null, ...$args) {
		$name = implode('<>', (array) ($name ?? static::$multitonDefaultName));
		$instance = (static::$multitonInstances[static::class][$name] ?? static::$multitonInstances[static::class][$name] = new static(...$args));
		$instance->multitonName = $name;
		return $instance;
	}
444595
public static Object instantiate(Class clazz) throws InstantiationException
    {
        Object result = null;
        try
        {
            result = ClassHelper.newInstance(clazz);
        }
        catch(IllegalAccessException e)
        {
            try
            {
                result = ClassHelper.newInstance(clazz, true);
            }
            catch(Exception e1)
            {
                throw new ClassNotPersistenceCapableException("Can't instantiate class '"
                        + (clazz != null ? clazz.getName() : "null")
                        + "', message was: " + e1.getMessage() + ")", e1);
            }
        }
        return result;
    }
194663
public function createCache($class, $args)
    {
        /** @var CacheInterface $cache */
        $reflection = new ReflectionClass($class);
        $cache = $reflection->newInstanceArgs($args);

        // Assign cache logger
        if ($this->logger && $cache instanceof LoggerAwareInterface) {
            $cache->setLogger($this->logger);
        }

        return $cache;
    }
1321427
protected function constructObject(/*# string */ $class, array $args)
    {
        $reflector = new \ReflectionClass($class);
        $constructor = $reflector->getConstructor();

        // not constructor defined
        if (is_null($constructor)) {
            $obj = $reflector->newInstanceWithoutConstructor();

        // normal class with constructor
        } else {
            $args = $this->matchArguments($constructor->getParameters(), $args);
            $obj = $reflector->newInstanceArgs($args);
        }

        return $obj;
    }
47478
public function newInstance($className, array $args = array())
    {
        // create and return a new instance
        $reflectionClass = $this->newReflectionClass($className);
        return $reflectionClass->newInstanceArgs($args);
    }
1120635
protected static function createObject($class, ...$args)
    {
        if (!is_subclass_of($class, Record::class)) {
            throw new \InvalidArgumentException(sprintf('Class: %s is not sub class of ' . Record::class, $class));
        }

        // TODO: Make Record support set DB after construct.
        try {
            return new $class(...$args);
        } catch (\Exception $e) {
            if ($e instanceof \InvalidArgumentException || $e->getPrevious() instanceof \PDOException) {
                return new NullRecord();
            }

            throw $e;
        }
    }
1315241
public static Object loadInstance(Class clazz, Object[] args, Object defaultValue) {
	if (args == null || args.length == 0) return loadInstance(clazz, defaultValue);
	try {
	    Class[] cArgs = new Class[args.length];
	    for (int i = 0; i < args.length; i++) {
		if (args[i] == null) cArgs[i] = Object.class;
		else cArgs[i] = args[i].getClass();
	    }
	    Constructor c = clazz.getConstructor(cArgs);
	    return c.newInstance(args);

	}
	catch (Throwable t) {
	    ExceptionUtil.rethrowIfNecessary(t);
	    return defaultValue;
	}

    }
9771
private function createInstance(ReflectionClass $reflection, array $arguments)
    {
        if (count($arguments)) {
            return $reflection->newInstanceArgs($arguments);
        }

        return $reflection->newInstance();
    }