PHP code example of comodojo / xmlrpc

1. Go to this page and download the library: Download comodojo/xmlrpc 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/ */

    

comodojo / xmlrpc example snippets


    // create an encoder instance
    $encoder = new \Comodojo\Xmlrpc\XmlrpcEncoder();

    // (optional) set character encoding
    $encoder->setEncoding("utf-8");

    // (optional) use ex:nil instead of nil
    $encoder->useExNil();

    // (optional) declare special types in $data
    $encoder->setValueType($data['a_value'], "base64");
    $encoder->setValueType($data['b_value'], "datetime");
    $encoder->setValueType($data['c_value'], "cdata");

    // Wrap actions in a try/catch block (see below)
    try {

        /* encoder actions */

    } catch (\Comodojo\Exception\XmlrpcException $xe) {

        /* someting goes wrong during encoding */

    } catch (\Exception $e) {

        /* generic error */

    }

    

    $call = $encoder->encodeCall("my.method", array("user"=>"john", "pass" => "doe")) ;

    

    $multicall = $encoder->encodeMulticall( array (
        "my.method" => array( "user"=>"john", "pass" => "doe" ),
        "another.method" => array( "value"=>"foo", "param" => "doe" ),
    );

    

    $multicall = $encoder->encodeMulticall( array (
        array( "my.method", array( "user"=>"john", "pass" => "doe" ) ),
        array( "another.method", array( "value"=>"foo", "param" => "doe" ) )
    );

    

    $response = $encoder->encodeResponse( array("success"=>true) );

    

    $error = $encoder->encodeError( 300, "Invalid parameters" );

    

    $values = $encoder->encodeResponse( array(

        array("success"=>true),

        array("faultCode"=>300, "faultString"=>"Invalid parameters")

    );

    

    // create a decoder instance
    $decoder = new \Comodojo\Xmlrpc\XmlrpcDecoder();

    // Wrap actions in a try/catch block (see below)
    try {

        /* decoder actions */

    } catch (\Comodojo\Exception\XmlrpcException $xe) {

        /* someting goes wrong during decoding */

    }

    

    $incoming_call = $decoder->decodeCall( $xml_data );

    

    array (
        0 => "my.method",
        1 =>  array(
            "param_1" => "value_1",
            "param_2" => "value_2",
            ...
        )
    )

    

    array (
        0 => array (
            0 => "my.method",
            1 =>  array(
                "param_1" => "value_1",
                "param_2" => "value_2",
                ...
            )
        ),
        1 => array (
            0 => "my.otherMethod",
            1 =>  array(
                "param_a" => "value_a",
                "param_b" => "value_b",
                ...
            )
        )
    )

    

    $returned_data = $decoder->decodeResponse( $xml_response_data );