Habari\XMLRPCClient::__call PHP Метод

__call() публичный Метод

This method allows any method name to be called on this object. The method called is the method called via RPC, within the scope defined in $this->scope.
public __call ( string $fname, array $args ) : array
$fname string The function name to call
$args array An array of arguments that were called with the function
Результат array The result array
    public function __call($fname, $args)
    {
        if ($this->scope != '') {
            $rpc_method = "{$this->scope}.{$fname}";
        } else {
            $rpc_method = $fname;
        }
        $rpx = new \SimpleXMLElement('<methodCall/>');
        $rpx->addChild('methodName', $rpc_method);
        if (count($args) > 0) {
            $params = $rpx->addchild('params');
            foreach ($args as $arg) {
                $param = $params->addchild('param');
                XMLRPCUtils::encode_arg($param, $arg);
            }
        }
        $request = new RemoteRequest($this->entrypoint, 'POST');
        $request->add_header('Content-Type: text/xml;charset=utf-8');
        $request->set_body($rpx->asXML());
        $request->execute();
        if ($request->executed()) {
            $response = $request->get_response_body();
            // @todo this should use the MultiByte class, not directly call mb_string functions
            $enc = mb_detect_encoding($response);
            $responseutf8 = mb_convert_encoding($response, 'UTF-8', $enc);
            try {
                // @todo this should use libxml_use_internal_errors() instead of trying to hide the PHP warning see the plugin info parsing code for an example
                $bit = ini_get('error_reporting');
                error_reporting($bit && !E_WARNING);
                $responsexml = new \SimpleXMLElement($responseutf8);
                error_reporting($bit);
                $tmp = $responsexml->xpath('//params/param/value');
                if (!($responsestruct = reset($tmp))) {
                    $tmp = $responsexml->xpath('//fault/value');
                    if (!($responsestruct = reset($tmp))) {
                        throw new \Exception(_t('Invalid XML response.'));
                    }
                }
                return XMLRPCUtils::decode_args($responsestruct);
            } catch (\Exception $e) {
                error_reporting($bit);
                return false;
            }
        }
    }