Call a static method on a class, bypassing visibility restrictions.

@param string|object $class   class name or instance
@param string        $method  method name
@param mixed         $args...

@return mixed
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);
    }
1057989
public static function instantiateClassByConstructor($class, $args)
    {
        switch (count($args)) {
            case 0:
                return new $class();
            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]);
            default:
                $rClass = new \ReflectionClass($class);
                return $rClass->newInstanceArgs($args);
        }
    }
236657
public function resolveMethod($class, $method, array $args = [])
    {
        if ( ! is_object($class)) {
            throw new Exception('Container::makeMethod except a object as the first parameter!');
        }

        $reflectionMethod = new ReflectionMethod($class, $method);
        $dependencies = $this->getMethodDependencies($reflectionMethod, $args);

        return $reflectionMethod->invokeArgs($class, $dependencies);
    }
26307
protected function invokeMethod($object, $method, array $arguments = array())
    {
        return $this->getReflectionMethod($object, $method)->invokeArgs($object, $arguments);
    }
5622
protected static function runCallback($method, $args)
	{
		$instance = static::resolveFacadeInstance();

		if(empty($args))
		{
			throw new InvalidArgumentException("Please provide an argument to this method");
			
		}

		switch (count($args))
		{
			case 0:
				return $instance->$method();

			case 1:
				return $instance->$method($args[0]);

			case 2:
				return $instance->$method($args[0], $args[1]);

			case 3:
				return $instance->$method($args[0], $args[1], $args[2]);

			case 4:
				return $instance->$method($args[0], $args[1], $args[2], $args[3]);

			default:
				return call_user_func_array(array($instance, $method), $args);
		}
	}
719679
public function popsCall($method, array &$arguments)
    {
        if ($this->liberatorReflector->hasMethod($method)) {
            $method = $this->liberatorReflector->getMethod($method);
            $method->setAccessible(true);

            return $this->popsProxySubValue(
                $method->invokeArgs($this->popsValue(), $arguments)
            );
        }

        return parent::popsCall($method, $arguments);
    }
1085258
protected function callAfterHooks($classInstance, $method, array $args = [])
    {
        $return = $this->callAfterAllHooks($classInstance, $method);

        if ($return !== null) {
            return $return;
        }

        $return = $this->callAfterMethodHooks($classInstance, $method, $args);

        if ($return !== null) {
            return $return;
        }

        $return = $this->callOnceAfterHooks($classInstance, $method, $args);

        if ($return !== null) {
            return $return;
        }
    }
440091
protected function callBeforeHooks($classInstance, $method, array $args = [])
    {
        $return = $this->callBeforeAllHooks($classInstance, $method);

        if ($return !== null) {
            return $return;
        }

        $return = $this->callBeforeMethodHooks($classInstance, $method, $args);

        if ($return !== null) {
            return $return;
        }

        $return = $this->callOnceBeforeHooks($classInstance, $method, $args);

        if ($return !== null) {
            return $return;
        }
    }
1076192
public function call($class, $method, &$a = null, &$b = null, &$c = null, &$d = null, &$e = null)
    {
        if (!is_callable(array($class, $method))) {
            return false;
        }

        try {
            $instance = Container::get($class);
            $instance->{$method}($a, $b, $c, $d, $e);
            $this->called[$method][$class] = array($class, $method);
            return array($a, $b, $c, $d, $e);
        } catch (Exception $exc) {
            return false;
        }
    }
468200
public static function newObject(string $class, array $args = [], $callGetClass = false)
    {
        $class = $callGetClass ? static::getClass($class) : $class;
        $rc = new \ReflectionClass($class);
        return $rc->newInstanceArgs($args);
    }
1055899
public function getMethodRequiredArgCount($class, string $method): int
    {
        $instance = new \ReflectionMethod($class, $method);
        $count = 0;
        // calculate method defined arguments count
        foreach ($instance->getParameters() as $arg) {
            if (!$arg->isOptional()) {
                $count++;
            }
        }

        return $count;
    }
820530
protected function callOnceAfterHooks($classInstance, $method, array $args = [])
    {
        $return = $this->callOnceAfterAllHooks($classInstance, $method, $args);

        if ($return !== null) {
            return $return;
        }

        $return = $this->callOnceAfterMethodHooks($classInstance, $method, $args);

        if ($return !== null) {
            return $return;
        }
    }
786246
public function staticProperty($class, $property, $args = array()) {
		if(!class_exists($class))
			return null;
		if(!property_exists($class, $property))
			return null;
		
		$vars = get_class_vars($class);
		return $vars[$property];
	}
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();
  }
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);
    }
29716
static function getMethodAnnotation($method, $annotationName, $class = NULL)
	{
		$method instanceof ReflectionMethod or $method = new ReflectionMethod($class, $method);

		return static::instance()->getMethodAnnotation($method, $annotationName);
	}
886287
public function callClassMethod($class, $method, ...$arguments)
	{
		$resolvedParameters = [];
		$reflectedClass = new ReflectionCLass($class);
		if (!$reflectedClass->hasMethod($method)) {
			throw new ReflectionException('Call to undefined method ' . $method);
		}

		$methodName = $method;
		$method = $reflectedClass->getMethod($method);
		$methodParameters = $method->getParameters();

		if (count($methodParameters) < 1) {
			return $method;
		}

		$resolvedParameters = array_map(function($param) use ($reflectedClass) {
			$type = $param->getType();

			if (preg_match("/(.*?)\\\/", $type)) {
				$type = (String) $type;
				return new $type;
			}

			if (!$param->isDefaultValueAvailable()) {
				return $param = '';
			}

			return $param->getDefaultValue();
			
		}, $methodParameters);

		$resolvedParameters = array_filter($resolvedParameters);
		$resolvedParameters = array_merge($resolvedParameters, $arguments);

		if ($methodName == '__construct') {
			return $reflectedClass->newInstanceArgs($resolvedParameters);
		}

		return $method->invokeArgs($class, $resolvedParameters);
	}