Home « Server software «
Documentation: services/xml_rpc_codec.php
Class XML_RPC_Codec extends Codec - Web service encoder and decoder
This script is a reference file of this system.
Voir aussi:
Licence: GNU Lesser General Public License
Auteurs:
- Bernard Paques bernard.paques@bigfoot.com
decode() - Parse a XML request according to the XML-RPC specification
function decode($data)
- $data - array the received $HTTP_RAW_POST_DATA
- returns array a status code (TRUE is ok) and the parsing result
Following tags are used for cdata conversion
- <base64>
- <boolean>
- <date>
- <double>
- <integer>
- <string>
Following tags are processed as leaves of the tree:
- </value>
- </methodName>
Following tags are processed as nodes of the tree
- <methodCall>: push 'methodCall' (stems 'methodName' and 'params')
- </methodCall>: pop 'methodCall'
- <methodResponse>: push 'methodResponse' (stem 'params' or 'fault')
- </methodResponse>: pop 'methodResponse'
- <fault>: push 'fault' (stems 'faultCode' and 'faultString')
- </fault>: pop 'fault'
- <params>: push 'params', then '-1' (list of anonymous stems)
- </params>: pop index, then pop 'params'
- <value> under an index: increment index (works for <params> and for <array>)
- </name>: push cdata (named stem)
- </member>: pop cdata
- <array>: push '-1' (list of anonymous stems)
- </array>: pop index
encode() - Encode some PHP value into XML
function encode($parameter, $type='')
- $parameter - mixed the parameter to encode
- $type='' - type, if any
- returns some XML
- array
- base64 - type has to be set explicitly for the encoding to take place
- boolean
- date - type has to be set explicitly to get a <dateTime.iso8601> element
- double
- integer
- struct
- string - type has to be set explicitly for the encoding to take place
export_request() - Build a request according to the XML-RPC specification
function export_request($service, $parameters = NULL)
- $service - string name of the remote service
- $parameters = NULL - mixed transmitted parameters, if any
- returns an array of which the first value indicates call success or failure
$service = 'search';
$parameter = array( 'search' => $_REQUEST['search']);
$result = $codec->export_request($service, $parameter);
if(!$result[0])
echo $result[1]; // print error code
else
... // send xml data from $result[1] to the remote web server
Resulting xml:
<?xml version="1.0"?>
<methodCall>
<methodName>search</methodName>
<params>
<param><value><struct>
<member><name>search</name><value><string>...</string></value></member>
</struct></value></param>
</params>
</methodCall>
Voir aussi:
export_response() - Build a response according to the XML-RPC specification
function export_response($values=NULL, $service=NULL)
- $values=NULL - mixed transmitted values, if any
- $service=NULL - string name of the remote service, if any
- returns an array of which the first value indicates call success or failure
$value = $codec->encode('hello world', 'string');
$result = $codec->export_response($value);
Resulting xml:
<?xml version="1.0"?>
<methodResponse>
<params>
<param><value><string>hello world</string></value></param>
</params>
</methodResponse>
Example to generate an error response:
$values = array('faultCode' => 123, 'faultString' => 'hello world');
$result = $codec->export_response($values);
Resulting xml:
<?xml version="1.0"?>
<methodResponse>
<fault>
<value><struct>
<member><name>faultCode</name><value><int>...</int></value></member>
<member><name>faultString</name><value>...</value></member>
</struct></value>
</fault>
</methodResponse>
Voir aussi:
import_request() - Parse a XML request according to the XML-RPC specification
function import_request($data)
- $data - array the received $HTTP_RAW_POST_DATA
- returns array the service called and the related input parameters
import_response() - Decode a XML response
function import_response($data, $headers=NULL, $parameters=NULL)
- $data - string the received HTTP body
- $headers=NULL - string the received HTTP headers
- $parameters=NULL - mixed the submitted parameters
- returns an array of which the first value indicates call success or failure
parse_tag_open() - Update the stack on opening tags
function parse_tag_open($parser, $tag, $attributes)
- $parser -
- $tag -
- $attributes -
- <methodCall>: push 'methodCall' (stems 'methodName' and 'params')
- <methodResponse>: push 'methodResponse' (stem 'params')
- <fault>: push 'fault' (stems 'faultCode' and 'faultString')
- <params>: push 'params', then push '-1' (list of anonymous stems)
- <array>: push '-1' (list of anonymous stems)
- <value> under an index: increment index (works for <params> and for <array>)
parse_cdata() - Capture cdata for further processing
function parse_cdata($parser, $cdata)
- $parser -
- $cdata -
parse_tag_close() - Update the stack on closing tags
function parse_tag_close($parser, $tag)
- $parser -
- $tag -
- </base64>
- </boolean>
- </date>
- </double>
- </integer>
- </string>
The result is updated on following tags:
- </value>
- </methodName>
The stack is updated on following tags:
- </methodCall>: pop 'methodCall'
- </methodResponse>: pop 'methodResponse'
- </fault>: pop 'fault'
- </params>: pop index, then pop 'params'
- </name>: push cdata (named stem)
- </member>: pop cdata
- </array>: pop index