Search by

kodhe / xmlrpcs

karyakode

Kodhe xmlrpcs library

Package info

github.com/kodhe/xmlrpcs

pkg:composer/kodhe/xmlrpcs

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.1.0 2026-09-29 12:58 UTC

This package is not auto-updated.

Last update: 2026-10-28 11:52:58 UTC


README

XML-RPC server-side library refactored from CodeIgniter 3's Xmlrpcs (namespace Kodhe\Framework\Xmlrpcs). Extends the kodhe/xmlrpc package (the Xmlrpc client class) — its only internal dependency. Suitable for exposing an RPC API: method listing, introspection (system.*), and multiCall.

Installation

composer require kodhe/xmlrpcs   # automatically pulls in kodhe/xmlrpc

Requirements: PHP >= 8.1, the xml extension; the Xmlrpc class must be loaded before Xmlrpcs (guaranteed by Composer's autoloader).

Quick Start

<?php

declare(strict_types=1);

use Kodhe\Framework\Xmlrpcs\Xmlrpcs;

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

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

$server->serve();   // reads php://input, dispatches, prints the XML response

Directory Structure

src/
└── Xmlrpcs.php     # Server class: method map, request parsing, dispatch
                    # (+ reuses Encoder/Decoder/Message from kodhe/xmlrpc)

Usage

1. Defining methods via the config array

Each entry uses exactly the same format as CI3's $config['webservices']:

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

Or set them in bulk after construction:

$server->set_methods($methodMapArray);

2. Adding methods one at a time

$server->add_to_map(
    'echo.hello',
    'fn_echo',                                  // function fn_echo($m) { ... }
    [[['name' => 'message', 'type' => 'string']]],
    'Returns the message that was sent.'
);

3. Callback methods & the request object

Callback functions receive a single argument: the decoded request object:

function postArticle($req)
{
    $params = $req->output_parameters();   // array of caller parameters
    // ... process ...
    return $req->send_response(42);        // return a value to the client
}

4. Built-in introspection methods

By default the server registers the system.* methods:

$server->set_system_methods();  // called automatically when a special 'i18n' config is present
// provides: system.listMethods, system.methodSignature,
//           system.methodHelp, system.multiCall

Clients can call them like this:

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

5. Manual request validation

if (!$server->verify_request($rawXml)) {
    http_response_code(400);
}
$request = $server->parseRequest($rawXml);   // request object ready for reuse

6. Integration as a CI3-style controller

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

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

API Reference (Xmlrpcs)

Method Description
__construct(array $config) Initialize + register the method map
initialize($config) Reset the configuration
serve() Process the incoming request (POST STDIN) → emit the XML response
add_to_map($method, $function, $sig, $doc) Register a single method
set_methods(array $methods) Replace the entire method map
set_system_methods() Enable system.* (listMethods, methodSignature, methodHelp, multicall)
verify_request(string $data) Check the validity of the request XML
parseRequest($data) Decode the body into a request object
listMethods($m) / methodSignature($m) / methodHelp($m) / multicall($m) system.* handlers

CodeIgniter 3 Compatibility

Dispatch behavior, signature format, fault codes, and the system.* methods are identical to CI_Xmlrpcs. The only difference is the namespace/class name (Xmlrpcs, extending Kodhe\Framework\Xmlrpc\Xmlrpc).

Notes

  • Always send the Content-Type: text/xml header before calling serve().
  • Callbacks that throw exceptions produce a fault -32700/internal error — handle errors inside your function so messages don't leak.
  • For authentication, check the username/password parameters inside the callback (no built-in middleware is provided).

Testing

vendor/bin/phpunit --filter Xmlrpcs