PHP code example of kodhe / xmlrpcs

1. Go to this page and download the library: Download kodhe/xmlrpcs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kodhe / xmlrpcs example snippets




declare(strict_types=1);

use Kodhe\Framework\Xmlrpcs\Xmlrpcs;

header('Content-Type: text/xml');

$server = new Xmlrpcs([
    'blog.post' => [
        'function' => 'postArticle',          // callable global atau method controller CI
        'signature' => [[
            ['name' => 'postId',   'type' => 'int'],
            ['name' => 'username', 'type' => 'string'],
            ['name' => 'password', 'type' => 'string'],
            ['name' => 'content',  'type' => 'struct'],
        ]],
        'docstring' => 'Publikasikan satu artikel blog.',
    ],
]);

$server->serve();   // baca php://input, dispatch, cetak XML respons

new Xmlrpcs([
    'nama.method' => [
        'function'  => 'callback_php',       // string nama fungsi / array call-able
        'signature' => [[[ ['name'=>'arg','type'=>'string'] ], ['returns','int'] ]],
        'docstring' => 'Penjelasan singkat',
    ],
]);

$server->set_methods($metodeMapArray);

$server->add_to_map(
    'echo.halo',
    'fn_echo',                                  // function fn_echo($m) { ... }
    [[['name' => 'pesan', 'type' => 'string']]],
    'Mengembalikan pesan yang dikirim.'
);

function postArticle($req)
{
    $params = $req->output_parameters();   // array parameter pemanggil
    // ... proses ...
    return $req->send_response(42);        // kembalikan nilai ke klien
}

$server->set_system_methods();  // dipanggil otomatis bila ada 'i18n' config khusus
// menyediakan: system.listMethods, system.methodSignature,
//              system.methodHelp, system.multiCall

$methods = $client->call('system.listMethods');

if (!$server->verify_request($rawXml)) {
    http_response_code(400);
}
$request = $server->parseRequest($rawXml);   // objek request siap dipakai ulang

class Webservice extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->library('xmlrpc');      // klien dulu...
        $this->load->library('xmlrpcs', $this->config->item('webservices'));
    }

    public function index()
    {
        if ($this->input->method() === 'post') {
            $this->xmlrpcs->serve();
        }
    }
}