Calls a class considering all routes.

@param *string $class class name
@param array   $args  arguments

@return object
540045
public function callArray($class, array $args = array())
    {
        //argument 1 must be a string
        Argument::i()->test(1, 'string');

        //get the true class
        $route = $this->get($class);
        
        //if route is already an abject
        if (is_object($route)) {
            //return it
            return $route;
        }
        
        //if the static method i exists
        if (method_exists($route, 'i')) {
            //instantiate it
            return forward_static_call_array(array($route, 'i'), $args);
        }
        
        //instantiate it
        $reflect = new \ReflectionClass($route);
        return $reflect->newInstanceArgs($args);
    }
110378
public function produce(string $class, array $args, string $selector = Injector::DEFAULT_SELECTOR, Injector $injector)
    {
        $const_name = $class . '::WDI_NO_AUTO';
        if (defined($const_name) && constant($const_name) === true)
        {
            throw new DIException("Cannot instantiate $class because $class::WDI_NO_AUTO is true");
        }

        try
        {
            $reflect = new ReflectionClass($class);

            $instance = null;
            $dc = $reflect->getDocComment();
            if (!empty($dc))
            {
                $dc = new DocComment($dc);
                $gen = $dc->getAnnotationTokens("generator");
                if (!empty($gen))
                {
                    $instance = $this->attemptGeneratorMethod($gen, $class, $args, $selector, $injector);
                }
            }

            if (null === $instance)
            {
                $constructor = $reflect->getConstructor();
                if (null === $constructor)
                    return $reflect->newInstance();

                if (!$constructor->isPublic())
                    throw new DIException("Class $class does not have a public constructor");

                $constructor_args = $this->determineArgumentsFor($constructor, $class, "constructor", $args, $selector, $injector);
                $instance = $reflect->newInstanceArgs($constructor_args);
            }
        }
        catch (DIException $e)
        {
            throw new DIException("Could not instantiate class $class", 0, $e);
        }

        return $instance;
    }
1250884
protected static function getSingleton($class = null)
    {
        //super magic sauce getting the callers class
        if (is_null($class) && function_exists('get_called_class')) {
            $class = get_called_class();
        }
        
        //get routed class, if any
        $class = Route::i()->get($class);
        
        //if it's not set
        if (!isset(self::$instances[$class])) {
            //set it
            self::$instances[$class] = self::getInstance($class);
        }
        
        //return the cached version
        return self::$instances[$class];
    }
547292
public static function callStatic($class, $method, $args = null)
    {
        $args   = \func_get_args();
        $class  = \array_shift($args);
        $method = \array_shift($args);

        $refl = new \ReflectionClass($class);
        $reflMethod = $refl->getMethod($method);
        $reflMethod->setAccessible(true);

        return $reflMethod->invokeArgs(null, $args);
    }
180599
public function loadClass($class)
    {
        foreach (spl_autoload_functions() as $func) {
            if (is_array($func) && $func[0] === $this) {
                continue;
            }
            $this->classList->push($class);
            if (call_user_func($func, $class)) {
                break;
            }
        }

        $this->classList->next();

        return true;
    }
438173
protected function callQueueMethodOnHandler($class, $method, $arguments)
	{
		$handler = (new ReflectionClass($class))->newInstanceWithoutConstructor();

		$handler->queue($this->resolveQueue(), 'Illuminate\Events\CallQueuedHandler@call', [
			'class' => $class, 'method' => $method, 'data' => serialize($arguments),
		]);
	}
538734
public function __simple(string $class, array $args)
    {
        $config = FrameworkTools::getEditionInfo();
        $autowired = $config->autowiring ?? false;
        $annotation = $config->annotation ?? false;
        $container = FrameworkContainer::getInstance();
        $builder = new \DI\ContainerBuilder();
        $builder->useAnnotations($annotation);
        $builder->useAutowiring($autowired);
        $container = $builder->build();
        $call = $container->get($class);
        try {
            $rs = $container->call($class."::__render", array($args));
        } catch (\RuntimeException $ex) {
            throw new \RuntimeException($ex->getMessage());
        }
    }
624737
public function newInstance(string $class, $args = [], string $selector = Injector::DEFAULT_SELECTOR)
    {
        if (!class_exists($class))
            throw new DIException("Class $class does not exist");

        if (isset($this->factories[$class]))
            return $this->factories[$class]->produce($class, $args, $selector, $this);

        return $this->default_factory->produce($class, $args, $selector, $this);
    }
1069044
static function instance($class, array $args = []) {
    // Get class name
    $class = static::getClass($class);
    // Count args
    switch (count($args)) {
      case 1:   return new $class($args[0]);
      case 2:   return new $class($args[0], $args[1]);
      case 3:   return new $class($args[0], $args[1], $args[2]);
      case 4:   return new $class($args[0], $args[1], $args[2], $args[3]);
      case 5:   return new $class($args[0], $args[1], $args[2], $args[3], $args[4]);
      case 6:   return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]);
      case 7:   return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]);
      case 8:   return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]);
      case 9:   return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]);
      case 10:  return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8], $args[9]);
    }
    // Return without args
    return new $class();
  }
204463
public function routeClass($routeClass = null)
    {
        deprecationWarning(
            'RouteBuilder::routeClass() is deprecated. ' .
            'Use RouteBuilder::setRouteClass()/getRouteClass() instead.'
        );
        if ($routeClass === null) {
            return $this->getRouteClass();
        }
        $this->setRouteClass($routeClass);
    }
745760
public function produce(string $class, array $args, string $selector, Injector $injector)
    {
        return call_user_func($this->function, $args);
    }
48961
public function push($class, $args = [], $retry = true, $queue = self::QUEUE)
    {
        $jobId = $this->idGenerator->generate();
        $this->atomicPush($jobId, $class, $args, $queue, $retry);

        return $jobId;
    }
939667
public function get(string $class_name, array $args = [])
    {
        $class_name = ltrim($class_name, '\\');
        $class_key  = strtolower($class_name);

        if (isset($this->instances[$class_key])) {
            return $this->instances[$class_key];
        }
        if (!isset($this->closures[$class_key])) {
            $this->closures[$class_key] = $this->getClosure($class_name, $class_key);
        }
        return $this->closures[$class_key]($args);
    }
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 );
	}
614602
private function load($class)
    {
        if ($this->isLoaded($class)) {
            throw new \InvalidArgumentException(sprintf(
                "Error loading class '%s', the class already exists",
                $class
            ));
        }

        if ($file = $this->findFile($class)) {
            return $this->loadFile($file, $class);
        }

        return false;
    }
881408
public static function getInstance($class, array $args, array $conf, string $confHash) {
        $rfClass = new ReflectionClass($class);
        if (!$rfClass->implementsInterface(IComponent::class)) {
            throw new InvalidArgumentException("class $class is not an instance of x2ts\\IComponent");
        }
        if ($rfClass->hasMethod('getInstance')) {
            return $rfClass->getMethod('getInstance')
                ->invoke(null, $args, $conf, $confHash);
        }
        /** @var IComponent $component */
        $component = $rfClass->newInstanceArgs($args);
        $rfClass->getMethod('saveConf')->invoke($component, $conf, $confHash);
        if ($rfClass->hasMethod('init')) {
            $rfClass->getMethod('init')->invoke($component);
        }
        return $component;
    }
659809
private function handle(string $class, array $args)
    {
        $latest = null;
        foreach ($this->catchers[$class] as $catcher) {
            $latest = $catcher(...$args);
        }
        return $latest;
    }