Skip to content

comodojo/xmlrpc

Repository files navigation

comodojo/xmlrpc

build Latest Stable Version Total Downloads Latest Unstable Version License Scrutinizer Code Quality Code Coverage Quality Gate Status Reliability Rating

Yet another php xmlrpc decoder/encoder.

This is the development branch, please do not use it in production

Main features:

  • support for nil and ex:nil
  • implements true, XML compliant, HTML numeric entities conversion
  • support for CDATA values

Installation

  • Using Composer

    Install composer, then:

    composer require comodojo/xmlrpc

Encoding

  • Create an encoder instance:

    // 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 */
    
    }
  • single call:

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

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

    Alternate syntax (duplicated-methods safe):

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

    $response = $encoder->encodeResponse( array("success"=>true) );
  • single call error response

    $error = $encoder->encodeError( 300, "Invalid parameters" );
  • multicall success/error (faultString and faultCode should be explicitly declared in $data)

    $values = $encoder->encodeResponse( array(
    
        array("success"=>true),
    
        array("faultCode"=>300, "faultString"=>"Invalid parameters")
    
    );

Decoding

  • create a decoder instance:

    // 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 */
    
    }
  • decode single or multicall

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

    In case of single request, method will return an array like:

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

    In case of multicall:

    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",
                ...
            )
        )
    )
  • decode response

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

Documentation

Contributing

Contributions are welcome and will be fully credited. Please see CONTRIBUTING for details.

License

comodojo/xmlrpc is released under the MIT License (MIT). Please see License File for more information.

Copyright (c) 2018 Marco Giovinazzi

For more information, visit comodojo.org.

About

Yet another php xmlrpc decoder/encoder

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •