Source for file NS_XML_RPC_Service_Handler.php
Documentation is available at NS_XML_RPC_Service_Handler.php
* nanoserv handlers - XML-RPC server
* Copyright (C) 2004-2010 Vincent Negrier aka. sIX <six@aegis-corp.org>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
* Require the HTTP server
require_once "nanoserv-compat/handlers/NS_HTTP_Service_Handler.php";
* XML-RPC Service handler class
* Convert a PHP variable to XML string representation
$ret .= "<i4>". $var. "</i4>";
$ret .= "<boolean>".(int) $var. "</boolean>";
$ret .= "<string>". $var. "</string>";
$ret .= "<double>". $var. "</double>";
if (self::Is_Assoc($var)) {
foreach ($var as $k=> $v) {
$ret .= "<name>". $k. "</name>";
$ret .= self::Variable_To_XML_String($v);
foreach ($var as $v) $ret .= self::Variable_To_XML_String($v);
$ret .= "</data></array>";
* Checks if given array is associative
static private function Is_Assoc($arr) {
* Convert a XMLRPC value stored in a SimpleXmlElement object to php variable
* @param SimpleXmlElement $xml
foreach ($xml as $type => $xvalue) break;
$value = (string) $xvalue;
$value = self::XML_Struct_To_Array($xvalue);
* Convert a XMLRPC struct or array stored in a SimpleXmlElement object to php array
* @param SimpleXmlElement $xml
foreach ($xml as $xtype=> $xelem) {
foreach ($xelem as $mprop=> $xval) {
$mval = self::XML_Value_To_Variable($xval);
foreach ($xelem as $xval) $ret[] = self::XML_Value_To_Variable($xval);
* Convert XMLRPC method call params stored in a SimpleXmlElement object to a php array
* @param SimpleXmlElement $xml
foreach ($xml as $topname=> $xparam) {
foreach ($xparam as $xvalue) $ret[] = self::XML_Value_To_Variable($xvalue);
* Add XMLRPC response envelope
* @param string $xml_result
return "<methodResponse><params><param>{$xml_result}</param></params></methodResponse>";
return "<methodResponse><fault><value><struct><member><name>faultCode</name><value><int>" . $e->getCode() . "</int></value></member><member><name>faultString</name><value><string>" . $e->getMessage() . "</string></value></member></struct></value></fault></methodResponse>";
foreach ($xreq as $name => $xtopelem) {
$method = (string) $xtopelem;
return self::XML_Add_MethodResponse_Envelope(self::Variable_To_XML_String($this->on_Call($method, isset ($params) ? self::XML_Params_To_Array($params) : NULL)));
return self::XML_Add_Fault_Envelope($e);
* Event called on XML-RPC method call
* The value returned by on_Call() will be sent back as the XMLRPC method call response
abstract public function on_Call($method, $args);
|