r\DatumConverter::nativeToFunction PHP Method

nativeToFunction() public method

public nativeToFunction ( $f )
    public function nativeToFunction($f)
    {
        if (is_object($f) && is_subclass_of($f, '\\r\\Query')) {
            return $this->wrapImplicitVar($f);
        }
        $reflection = new ReflectionFunction($f);
        $args = array();
        foreach ($reflection->getParameters() as $param) {
            $args[] = new RVar($param->getName());
        }
        $result = $reflection->invokeArgs($args);
        if (!(is_object($result) && is_subclass_of($result, "\\r\\Query"))) {
            if (!isset($result)) {
                // In case of null, assume that the user forgot to add a return.
                // If null is the intended value, r\expr() should be wrapped around the return value.
                throw new RqlDriverError("The function did not evaluate to a value (missing return?). If the function is intended to return `null,` please use `return rxpr(null);`.");
            } else {
                $result = $this->nativeToDatum($result);
            }
        }
        return new RFunction($args, $result);
    }