Craft\ElementApiController::_callWithParams PHP Method

_callWithParams() private method

Calls a given function. If any params are given, they will be mapped to the function's arguments.
private _callWithParams ( $func, $params ) : mixed
$func The function to call
$params Any params that should be mapped to function arguments
return mixed The result of the function
    private function _callWithParams($func, $params)
    {
        if (!$params) {
            return call_user_func($func);
        }
        $ref = new \ReflectionFunction($func);
        $args = [];
        foreach ($ref->getParameters() as $param) {
            $name = $param->getName();
            if (isset($params[$name])) {
                if ($param->isArray()) {
                    $args[] = is_array($params[$name]) ? $params[$name] : [$params[$name]];
                } else {
                    if (!is_array($params[$name])) {
                        $args[] = $params[$name];
                    } else {
                        return false;
                    }
                }
            } else {
                if ($param->isDefaultValueAvailable()) {
                    $args[] = $param->getDefaultValue();
                } else {
                    return false;
                }
            }
        }
        return $ref->invokeArgs($args);
    }