Yet another php xmlrpc decoder/encoder.
Main features:
- support for
nil
andex:nil
- implements true, XML compliant, HTML numeric entities conversion
- support for CDATA values
-
Using Composer
Install composer, then:
composer require comodojo/xmlrpc 1.0.*
-
Manually
Download zipball from GitHub, extract it, include
src/XmlrpcEncoder.php
,src/XmlrpcDecoder.php
andsrc/Exception/XmlrpcException.php
in your project.
-
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") );
-
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 );
Contributions are welcome and will be fully credited. Please see CONTRIBUTING for details.
comodojo/xmlrpc
is released under the MIT License (MIT). Please see License File for more information.