cvs: pear /XML_RPC2 Makefile package.xml /XML_RPC2/XML/RPC2 Backend.php Client.php Exception.php Server.php Value.php /XML_RPC2/XML/RPC2/Backend/Php
Client.php Request.php Response.php Server.php Value.php /XML_RPC2/XML/RPC2/Backend/Php/Value Array.php Base64.php Boolean.php Datetime.php
Double.php Integer.php Scalar.php String.php Struct.php /XML_RPC2/XML/RPC2/Backend/Xmlrpcext Client.php Server.php Value.php
/XML_RPC2/XML/RPC2/Server CallHandler.php Method.php /XML_RPC2/XML/RPC2/Server/CallHandler Class.php Instance.php /XML_RPC2/XML/RPC2/Util
HTTPRequest.php /XML_RPC2/docs Makefile /XML_RPC2/docs/tutorials XML_RPC2.lyx /XML_RPC2/tests Makefile /XML_RPC2/tests/XML_RPC2/phpBackend/client
faultFromPython.phpt okFromPython.phpt protocolError.phpt /XML_RPC2/tests/XML_RPC2/phpBackend/decoding array.phpt base64.phpt boolean.phpt
datetime.phpt double.phpt faultResponse.phpt integer.phpt integer2.phpt request.phpt response.phpt string.phpt struct.phpt
/XML_RPC2/tests/XML_RPC2/phpBackend/encoding array.phpt base64.phpt boolean.phpt datetime.phpt datetime1.phpt datetime2.phpt datetime3.phpt
datetime4.phpt double.phpt integer.phpt request.phpt response.phpt response2.phpt string.phpt struct.phpt /XML_RPC2/tests/XML_RPC2/phpBackend/server
invalidXMLRequest.phpt nonexistantMethod.phpt normalRequest.phpt /XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client faultFromPython.phpt
okFromPython.phpt protocolError.phpt valueCreateFromNative.phpt /XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server invalidXMLRequest.phpt
nonexistantMethod.phpt normalRequest.phpt /XML_RPC2/tests/lib run-tests tests-config /XML_RPC2/util filelist.sh indent.xsl
| From: | Sergio Carvalho | Date: | Tue, 29 Nov 2005 21:41:29 +0000 |
| Subject: | cvs: pear /XML_RPC2 Makefile package.xml /XML_RPC2/XML/RPC2 Backend.php Client.php Exception.php Server.php Value.php /XML_RPC2/XML/RPC2/Backend/Php Client.php Request.php Response.php Server.php Value.php /XML_RPC2/XML/RPC2/Backend/Php/Value Array.php Base64.php Boolean.php Datetime.php Double.php Integer.php Scalar.php String.php Struct.php /XML_RPC2/XML/RPC2/Backend/Xmlrpcext Client.php Server.php Value.php /XML_RPC2/XML/RPC2/Server CallHandler.php Method.php /XML_RPC2/XML/RPC2/Server/CallHandler Class.php Instance.php /XML_RPC2/XML/RPC2/Util HTTPRequest.php /XML_RPC2/docs Makefile /XML_RPC2/docs/tutorials XML_RPC2.lyx /XML_RPC2/tests Makefile /XML_RPC2/tests/XML_RPC2/phpBackend/client faultFromPython.phpt okFromPython.phpt protocolError.phpt /XML_RPC2/tests/XML_RPC2/phpBackend/decoding array.phpt base64.phpt boolean.phpt datetime.phpt double.phpt faultResponse.phpt integer.phpt integer2.phpt request.phpt response.phpt string.phpt struct.phpt /XML_RPC2/tests/XML_RPC2/phpBackend/encoding array.phpt base64.phpt boolean.phpt datetime.phpt datetime1.phpt datetime2.phpt datetime3.phpt datetime4.phpt double.phpt integer.phpt request.phpt response.phpt response2.phpt string.phpt struct.phpt /XML_RPC2/tests/XML_RPC2/phpBackend/server invalidXMLRequest.phpt nonexistantMethod.phpt normalRequest.phpt /XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client faultFromPython.phpt okFromPython.phpt protocolError.phpt valueCreateFromNative.phpt /XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server invalidXMLRequest.phpt nonexistantMethod.phpt normalRequest.phpt /XML_RPC2/tests/lib run-tests tests-config /XML_RPC2/util filelist.sh indent.xsl |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-36598@lists.php.net to get a copy of this message | ||
sergiosgc Tue Nov 29 16:41:29 2005 EDT
Added files:
/pear/XML_RPC2 Makefile package.xml
/pear/XML_RPC2/XML/RPC2 Backend.php Client.php Exception.php
Server.php Value.php
/pear/XML_RPC2/XML/RPC2/Backend/Php Client.php Request.php
Response.php Server.php
Value.php
/pear/XML_RPC2/XML/RPC2/Backend/Php/Value Array.php Base64.php
Boolean.php Datetime.php
Double.php Integer.php
Scalar.php String.php
Struct.php
/pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext Client.php Server.php
Value.php
/pear/XML_RPC2/XML/RPC2/Server CallHandler.php Method.php
/pear/XML_RPC2/XML/RPC2/Server/CallHandler Class.php Instance.php
/pear/XML_RPC2/XML/RPC2/Util HTTPRequest.php
/pear/XML_RPC2/docs Makefile
/pear/XML_RPC2/docs/tutorials XML_RPC2.lyx
/pear/XML_RPC2/tests Makefile
/pear/XML_RPC2/tests/XML_RPC2/phpBackend/client
faultFromPython.phpt
okFromPython.phpt
protocolError.phpt
/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding array.phpt
base64.phpt
boolean.phpt
datetime.phpt
double.phpt
faultResponse.phpt
integer.phpt
integer2.phpt
request.phpt
response.phpt
string.phpt
struct.phpt
/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding array.phpt
base64.phpt
boolean.phpt
datetime.phpt
datetime1.phpt
datetime2.phpt
datetime3.phpt
datetime4.phpt
double.phpt
integer.phpt
request.phpt
response.phpt
response2.phpt
string.phpt
struct.phpt
/pear/XML_RPC2/tests/XML_RPC2/phpBackend/server
invalidXMLRequest.phpt
nonexistantMethod.phpt
normalRequest.phpt
/pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client
faultFromPython.phpt
okFromPython.phpt
protocolError.phpt
valueCreateFromNative.phpt
/pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server
invalidXMLRequest.phpt
nonexistantMethod.phpt
normalRequest.phpt
/pear/XML_RPC2/tests/lib run-tests tests-config
/pear/XML_RPC2/util filelist.sh indent.xsl
Log:
Initial XML_RPC2 import
http://cvs.php.net/co.php/pear/XML_RPC2/package.xml?r=1.1&p=1 Index: pear/XML_RPC2/package.xml +++ pear/XML_RPC2/package.xml <?xml version="1.0"?> <package version="1.0"> <!-- $Id: package.xml,v 1.1 2005/11/29 21:41:26 sergiosgc Exp $ --> <name>XML_RPC2</name> <summary>XML-RPC client/server library</summary> <description> XML_RPC2 is a pear package providing XML_RPC client and server services. XML-RPC is a simple remote procedure call protocol built using HTTP as transport and XML as encoding. As a client library, XML_RPC2 is capable of creating a proxy class which exposes the methods exported by the server. As a server library, XML_RPC2 is capable of exposing methods from a class or object instance, seamlessly exporting local methods as remotely callable procedures. </description> <license>LGPL</license> <maintainers> <maintainer> <user>sergiosgc</user> <role>lead</role> <name>Sérgio Carvalho</name> <email>sergio.carvalho@portugalmail.com</email> </maintainer> </maintainers> <release> <version>0.0.5</version> <state>alpha</state> <date>2005-09-07</date> <notes> Implemented changes requested during package voting </notes> <filelist> <dir name="XML" role="php"> <dir name="RPC2" role="php"> <dir name="Backend" role="php"> <dir name="Php" role="php"> <file name="Client.php"/> <file name="Request.php"/> <file name="Response.php"/> <file name="Server.php"/> <dir name="Value" role="php"> <file name="Array.php"/> <file name="Base64.php"/> <file name="Boolean.php"/> <file name="Datetime.php"/> <file name="Double.php"/> <file name="Integer.php"/> <file name="Scalar.php"/> <file name="String.php"/> <file name="Struct.php"/> </dir> <file name="Value.php"/> </dir> <dir name="Xmlrpcext" role="php"> <file name="Client.php"/> <file name="Server.php"/> <file name="Value.php"/> </dir> </dir> <file name="Backend.php"/> <file name="Client.php"/> <file name="Exception.php"/> <dir name="Server" role="php"> <dir name="CallHandler" role="php"> <file name="Class.php"/> <file name="Instance.php"/> </dir> <file name="CallHandler.php"/> <file name="Method.php"/> </dir> <file name="Server.php"/> <dir name="Util" role="php"> <file name="HTTPRequest.php"/> </dir> <file name="Value.php"/> </dir> </dir> <dir name="XML_RPC2" role="test"> <dir name="phpBackend" role="test"> <dir name="client" role="test"> <file name="faultFromPython.phpt"/> <file name="okFromPython.phpt"/> <file name="protocolError.phpt"/> </dir> <dir name="decoding" role="test"> <file name="array.phpt"/> <file name="base64.phpt"/> <file name="boolean.phpt"/> <file name="datetime.phpt"/> <file name="double.phpt"/> <file name="faultResponse.phpt"/> <file name="integer2.phpt"/> <file name="integer.phpt"/> <file name="request.phpt"/> <file name="response.phpt"/> <file name="string.phpt"/> <file name="struct.phpt"/> </dir> <dir name="encoding" role="test"> <file name="array.phpt"/> <file name="base64.phpt"/> <file name="boolean.phpt"/> <file name="datetime1.phpt"/> <file name="datetime2.phpt"/> <file name="datetime3.phpt"/> <file name="datetime4.phpt"/> <file name="datetime.phpt"/> <file name="double.phpt"/> <file name="integer.phpt"/> <file name="request.phpt"/> <file name="response2.phpt"/> <file name="response.phpt"/> <file name="string.phpt"/> <file name="struct.phpt"/> </dir> <dir name="server" role="test"> <file name="invalidXMLRequest.phpt"/> <file name="nonexistantMethod.phpt"/> <file name="normalRequest.phpt"/> </dir> </dir> <dir name="xmlrpcextBackend" role="test"> <dir name="client" role="test"> <file name="faultFromPython.phpt"/> <file name="okFromPython.phpt"/> <file name="protocolError.phpt"/> <file name="valueCreateFromNative.phpt"/> </dir> <dir name="server" role="test"> <file name="invalidXMLRequest.phpt"/> <file name="nonexistantMethod.phpt"/> <file name="normalRequest.phpt"/> </dir> </dir> </dir> </filelist> <deps> <dep type="php" rel="ge" version="5.0.0"/> <dep type="pkg" rel="ge" version="1.0b1">PEAR</dep> </deps> </release> </package> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend.php +++ pear/XML_RPC2/XML/RPC2/Backend.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; /* }}} */ /** * XML_RPC Backend class. The backend is responsible for the actual execution of * a request, as well as payload encoding and decoding. * * The only external usage of this class is when explicitely setting the backend, as in * <code> * XML_RPC2_Backend::setBackend('php'); * // or * XML_RPC2_Backend::setBackend('xmlrpcext'); * </code> * Note that if you do not explicitely set the backend, it will be selected automatically. * * Internally, this class provides methods to obtain the relevant backend classes: * - The server class * - The client class * - The value class * * @author Sérgio Carvalho * @package XML_RPC2 */ abstract class XML_RPC2_Backend { protected static $currentBackend; /* setBackend {{{ */ /** * Backend setter. * * Currently, two backends exist: 'php' and 'XMLRPCext'. * The PHP backend has no external dependencies, while the xmlrpcext * requires the xmlrpc extension. * * The XMLRPCext backend is quite faster, and will be automatically * selected when no explicit backend has been set and the extension * is available. * * @param string The backend to select. Either 'php' or 'XMLRPCext'. */ public static function setBackend($backend) { $backend = ucfirst(strtolower($backend)); if ( $backend != 'Php' && $backend != 'Xmlrpcext' ) { throw new XML_RPC2_Exception(sprintf('Backend %s does not exist', $backend)); } if ( $backend == 'Xmlrpcext' && !function_exists('xmlrpc_server_create') && !( // TODO Use PEAR::loadExtension once PEAR passes PHP5 unit tests (E_STRICT compliance, namely) @dl('php_xmlrpc' . PHP_SHLIB_SUFFIX) || @dl('xmlrpc' . PHP_SHLIB_SUFFIX) ) ) { throw new XML_RPC2_Exception('Unable to load xmlrpc extension.'); } self::$currentBackend = $backend; } /* }}} */ /* getBackend {{{ */ /** * Backend getter. * * Return the current backend name. If no backend was previously selected * elect one and set it. * * The xmlrpcext backend is preferred, and will be automatically * selected when no explicit backend has been set and the xmlrpc * extension exists. If it does not exist, then the php backend is * selected. * * @return string The current backend */ protected static function getBackend() { if (!isset(self::$currentBackend)) { try { self::setBackend('XMLRPCext'); // We prefer this one } catch (XML_RPC2_Exception $e) { // TODO According to PEAR CG logging should occur here self::setBackend('php'); // But will settle with this one in case of error } } return self::$currentBackend; } /* }}} */ /* getServerClassname {{{ */ /** * Include the relevant php files for the server class, and return the backend server * class name. * * @return string The Server class name */ public static function getServerClassname() { require_once(sprintf('XML/RPC2/Backend/%s/Server.php', self::getBackend())); return sprintf('XML_RPC2_Backend_%s_Server', self::getBackend()); } /* }}} */ /* getClientClassname {{{ */ /** * Include the relevant php files for the client class, and return the backend client * class name. * * @return string The Client class name */ public static function getClientClassname() { require_once(sprintf('XML/RPC2/Backend/%s/Client.php', self::getBackend())); return sprintf('XML_RPC2_Backend_%s_Client', self::getBackend()); } /* }}} */ /* getValueClassname {{{ */ /** * Include the relevant php files for the value class, and return the backend value * class name. * * @return string The Value class name */ public static function getValueClassname() { require_once(sprintf('XML/RPC2/Backend/%s/Value.php', self::getBackend())); return sprintf('XML_RPC2_Backend_%s_Value', self::getBackend()); } /* }}} */ } http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Client.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Client.php +++ pear/XML_RPC2/XML/RPC2/Client.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend.php'; /* }}} /* /** * XML_RPC client class. Use this class to access remote methods. * * To use this class, construct it providing the server URL and method prefix. * Then, call remote methods on the new instance as if they were local. * * Example: * <code> * require_once 'XML_RPC2/Client.php'; * * $client = XML_RPC2_Client('http://xmlrpc.example.com/1.0/', 'example.'); * $result = $client->hello('Sérgio'); * print($result); * </code> * * The above example will call the example.hello method on the xmlrpc.example.com * server, under the /1.0/ URI. * * @package XML_RPC2 * @author Sérgio Carvalho */ abstract class XML_RPC2_Client { /* uri Field {{{ */ /** Holds the uri for the XML_RPC server */ protected $_uri = null; /** uri setter */ protected function setUri($uri) { if (!$uriParse = parse_url($uri)) { throw new XML_RPC2_InvalidUriException(sprintf('Client URI \'%s\' is not valid', $uri)); } $this->_uri = $uriParse; foreach (array_keys($this->_uri) as $key) { $this->_uri[$key] = urldecode($this->_uri[$key]); } $this->_uri['uri'] = $uri; } /** uri getter */ protected function getUri() { return $this->_uri['uri']; } /* }}} */ /* proxy Field {{{ */ /** Holds the proxy server data */ protected $_proxy = null; /** proxy setter */ protected function setProxy($proxy) { if (is_null($proxy)) { $this->_proxy = null; return; } if (!$proxyParse = parse_url($proxy)) throw new XML_RPC2_InvalidProxyException(sprintf('Proxy URI \'%s\' is not valid', $proxy)); $this->_proxy = $proxyParse; foreach (array_keys($this->_proxy) as $key) { $this->_proxy[$key] = urldecode($this->_proxy[$key]); } $this->_proxy['uri'] = $proxy; } /** proxy getter */ protected function getProxy() { return $this->_proxy['uri']; } /* }}} */ /* prefix Field {{{ */ /** Holds the prefix to prepend to method names */ protected $_prefix = null; /** prefix setter */ protected function setPrefix($prefix) { $this->_prefix = $prefix; } /** prefix getter */ protected function getPrefix() { return $this->_prefix; } /* }}} */ /* debug Field {{{ */ /** Holds the debug flag */ protected $_debug = false; /** debug setter */ public function setDebug($debug) { $this->_debug = $debug; } /** debug getter */ public function getDebug() { return $this->_debug; } /* }}} */ /* remoteCall(abstract) {{{ */ /** * remoteCall executes the XML-RPC call, and returns the result * * @param string Method name * @param array Parameters */ public abstract function remoteCall($methodName, $parameters); /* }}} */ /* constructor {{{ */ /** * Construct a new XML_RPC2_Client. * * To create a new XML_RPC2_Client, a URI must be provided (e.g. http://xmlrpc.example.com/1.0/). * Optionally, a prefix may be set, wich will be prepended to method names, before calling. * Prefixes are extremely useful namely when method names contain a period '.' turning them invalid * under PHP syntax. * Optionally, an encoding may be set. If set, it will be indicated in the request XML document, and * the response will be converted from its encoding to the designated encoding. * The fifth parameter, optional, allows for debugging to be turned on, by passing a boolean true value. * * @param string URI for the XML-RPC server * @param string (optional) Prefix to prepend on all called functions (defaults to '') * @param string (optional) Proxy server URI (defaults to no proxy) * */ protected function __construct($uri, $prefix = '', $proxy = null) { $this->setUri($uri); $this->setProxy($proxy); $this->setPrefix($prefix); } /* }}} */ /* create {{{ */ /** * Factory method to select, create and return a XML_RPC2_Client backend * * To create a new XML_RPC2_Client, a URI must be provided (e.g. http://xmlrpc.example.com/1.0/). * * Optionally, a prefix may be set, wich will be prepended to method names, before calling. * Prefixes are extremely useful namely when method names contain a period '.' turning them invalid * under PHP syntax. * * You may also set a proxy server, through where the requests will be sent. * * @param string URI for the XML-RPC server * @param string (optional) Prefix to prepend on all called functions (defaults to '') * @param string (optional) Proxy server URI (defaults to no proxy) * */ public static function create($uri, $prefix = '', $proxy = null) { $backend = XML_RPC2_Backend::getClientClassname(); return new $backend($uri, $prefix, $proxy); } /* }}} */ /* __call {{{ */ /** * __call Catchall. This method catches remote method calls and provides for remote forwarding. * * If the parameters are native types, this method will use XML_RPC_Value::createFromNative to * convert it into an XML-RPC type. Whenever a parameter is already an instance of XML_RPC_Value * it will be used as provided. It follows that, in situations when XML_RPC_Value::createFromNative * proves inacurate -- as when encoding DateTime values -- you should present an instance of * XML_RPC_Value in lieu of the native parameter. * * @param string Method name * @param array Parameters * @return mixed The call result, already decoded into native types */ public function __call($methodName, $parameters) { $args = array($methodName, $parameters); return @call_user_func_array( array($this, 'remoteCall'), $args ); } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Exception.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Exception.php +++ pear/XML_RPC2/XML/RPC2/Exception.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC2 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** * XML_RPC2 base exception class. All XML_RPC2 originated exceptions inherit from XML_RPC2_Exception * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Exception extends Exception { } /* Encoding and decoding values exceptions {{{ /** * XML_RPC2_InvalidTypeException is thrown whenever an invalid XML_RPC type is used in an operation * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_InvalidTypeException extends XML_RPC2_Exception { } /** * XML_RPC2_InvalidTypeException is thrown when creating DateTime value objects from invalid string datetime representations * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_InvalidDateFormatException extends XML_RPC2_Exception { } /** * XML_RPC2_EncodeException is thrown whenever a class is asked to encode itself in XML with invalid or not enough data. * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_EncodeException extends XML_RPC2_Exception { } /** * XML_RPC2_DecodeException is thrown whenever there is a problem decoding transport XML * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_DecodeException extends XML_RPC2_Exception { } /** * XML_RPC2_InvalidTypeEncodeException is thrown whenever a class is asked to encode itself and provided a PHP type * that can't be translated to XML_RPC * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_InvalidTypeEncodeException extends XML_RPC2_Exception { } /* }}} */ /** * XML_RPC2_InvalidUriException is thrown whenever the XML_RPC2 client is asked to use an invalid uri * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_InvalidUriException extends XML_RPC2_Exception { } /** * XML_RPC2_FaultException signals a XML-RPC response that contains a fault element instead of a regular params element. * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_FaultException extends XML_RPC2_Exception { /* vars {{{ */ protected $faultCode = null; /* }}} */ /* constructor {{{ */ /** Construct a new XML_RPC2_FaultException with a given message string and fault code * * @param string The message string, corresponding to the faultString present in the response body * @param string The fault code, corresponding to the faultCode in the response body */ function __construct($messageString, $faultCode) { parent::__construct($messageString); $this->faultCode = $faultCode; } /* }}} */ /* getFaultCode {{{ */ /** * faultCode getter */ public function getFaultCode() { return $this->faultCode; } /* }}} */ /* createFromDecode {{{ */ public static function createFromDecode($xml) { require_once 'XML/RPC2/Backend/Php/Value.php'; // This is the only way I know of creating a new Document rooted in the provided simpleXMLFragment (needed for the xpath expressions that does not segfault sometimes $xml = simplexml_load_string($xml->asXML()); $struct = XML_RPC2_Backend_Php_Value::createFromDecode($xml->value)->getNativeValue(); if (!(is_array($struct) && array_key_exists('faultString', $struct) && array_key_exists('faultCode', $struct))) throw new XML_RPC2_DecodeException('Unable to decode XML-RPC fault payload'); return new XML_RPC2_FaultException( $struct['faultString'], $struct['faultCode'] ); } /* }}} */ } /** * XML_RPC2_UnknownMethodException is thrown when a non-existent method is remote-called * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_UnknownMethodException extends XML_RPC2_Exception { } /** * XML_RPC2_TransportException signal transport level exceptions that stop requests from reaching the server * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_TransportException extends XML_RPC2_Exception { } /** * XML_RPC2_ReceivedInvalidStatusCodeExceptionextends is thrown whenever the XML_RPC2 response to a request does not return a 200 http status code. * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_ReceivedInvalidStatusCodeException extends XML_RPC2_TransportException { } /** * XML_RPC2_CurlError is thrown whenever an error is reported by the low level HTTP cURL library * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_CurlException extends XML_RPC2_TransportException { } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Server.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Server.php +++ pear/XML_RPC2/XML/RPC2/Server.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend.php'; /* }}} */ /** * XML_RPC2_Server is the frontend class for exposing PHP functions via XML-RPC. * * Exporting a programatic interface via XML-RPC using XML_RPC2 is exceedingly easy: * * The first step is to assemble all methods you wish to export into a class. You may either * create a (abstract) class with exportable methods as static, or use an existing instance * of an object. * * You'll then need to document the methods using PHPDocumentor tags. XML_RPC2 will use the * documentation for server introspection. You'll get something like this: * * <code> * class ExampleServer { * /** * * hello says hello * * * * @param string Name * * @return string Greetings * {@*} * public static function hello($name) { * return "Hello $name"; * } * } * </code> * * Now, instantiate the server, using the Factory method to select a backend and a call handler for you: * <code> * require_once 'XML/RPC2/Server.php'; * $server = XML_RPC2_Server::create('ExampleServer'); * $server->handleCall(); * </code> * * This will create a server exporting all of the 'ExampleServer' class' methods. If you wish to export * instance methods as well, pass an object instance to the factory instead: * <code> * require_once 'XML/RPC2/Server.php'; * $server = XML_RPC2_Server::create(new ExampleServer()); * $server->handleCall(); * </code> * */ abstract class XML_RPC2_Server { /* callHandler Field {{{ */ /** The call handler is responsible for executing the server exported methods */ protected $_callHandler = null; /** * callHandler setter * * @param object Object that will receive calls for remote methods */ protected function setCallHandler($callHandler) { $this->_callHandler = $callHandler; } /** * callHandler getter * * @return object Object that will receive calls for remote methods */ protected function getCallHandler() { return $this->_callHandler; } /* }}} */ /* aliases Field {{{ */ /** Holds method aliases */ protected $_aliases = array(); /** aliases setter */ protected function setAliases($aliases) { $this->_aliases = $aliases; } /** aliases appender */ protected function addAlias($alias) { $this->_aliases[] = $alias; } /** aliases getter */ protected function getAliases() { return $this->_aliases; } /* }}} */ /* Constructor {{{ */ /** * Create a new XML-RPC Server. * * @param object Call handler. The call handler will receive a method call for each remote call received. */ protected function __construct($callHandler) { $this->_callHandler = $callHandler; } /* }}} */ /* create {{{ */ /** * Factory method to select a backend and return a new XML_RPC2_Server based on the backend * * @param mixed Call target. Either a class name or an object instance. * @param string Method prefix. This prefix will be prepended to exported method names. (Defaults to '') * @param object Call handler object. Defaults to selecting a CallHandler suited to the received call target * * @return XML_RPC2_Server A server class instance */ public static function create($callTarget, $prefix = '', $callHandler = null) { $backend = XML_RPC2_Backend::getServerClassname(); // Find callHandler class if (is_null($callHandler)) { if (is_object($callTarget)) { // Delegate calls to instance methods require_once 'XML/RPC2/Server/CallHandler/Instance.php'; $callHandler = new XML_RPC2_Server_CallHandler_Instance($callTarget, $prefix); } else { // Delegate calls to static class methods require_once 'XML/RPC2/Server/CallHandler/Class.php'; $callHandler = new XML_RPC2_Server_CallHandler_Class($callTarget, $prefix); } } return new $backend($callHandler); } /* }}} */ /* handleCall(abstract) {{{ */ /** * Receive the XML-RPC request, decode the HTTP payload, delegate execution to the call handler, and output the encoded call handler response. * */ public abstract function handleCall(); /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Value.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Value.php +++ pear/XML_RPC2/XML/RPC2/Value.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend.php'; /* }}} */ /** * XML_RPC value abstract class. All XML_RPC value classes inherit from XML_RPC2_Value * * @author Sérgio Carvalho * @package XML_RPC2 */ abstract class XML_RPC2_Value { /* createFromNative {{{ */ /** * Factory method that constructs the appropriate XML-RPC encoded type value * * @param mixed Value to be encode * @param string (optional) Explicit XML-RPC type as enumerated in the XML-RPC spec (defaults to automatically selected type) * @return mixed The encoded value */ public static function createFromNative($value, $explicitType = null) { return @call_user_func(array(XML_RPC2_Backend::getValueClassname(), 'createFromNative'), $value, $explicitType); } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Client.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Client.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Client.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Util/HTTPRequest.php'; require_once 'XML/RPC2/Value.php'; require_once 'XML/RPC2/Client.php'; require_once 'XML/RPC2/Backend/Php/Request.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; /* }}} /* /** * XML_RPC client backend class. This is the default, all-php XML_RPC client backend. * * This backend does not require the xmlrpc extension to be compiled in. It implements * XML_RPC based on the always present DOM and SimpleXML PHP5 extensions. * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Client extends XML_RPC2_Client { /* constructor {{{ */ /** * Construct a new XML_RPC2_Client PHP Backend. * * To create a new XML_RPC2_Client, a URI must be provided (e.g. http://xmlrpc.example.com/1.0/). * Optionally, a prefix may be set, wich will be prepended to method names, before calling. * Prefixes are extremely useful namely when method names contain a period '.' turning them invalid * under PHP syntax. * * @param string URI for the XML-RPC server * @param string (optional) Prefix to prepend on all called functions * @param string (optional) Proxy server URI * */ function __construct($uri, $prefix = '', $proxy = null) { parent::__construct($uri, $prefix, $proxy); } /* }}} */ /* remoteCall {{{ */ /** * remoteCall executes the XML-RPC call, and returns the result * * @param string Method name * @param array Parameters */ public function remoteCall($methodName, $parameters) { $request = new XML_RPC2_Backend_Php_Request($this->getPrefix() . $methodName); $request->setParameters($parameters); $request = $request->encode(); $uri = $this->getUri(); $httpRequest = new XML_RPC2_Util_HTTPRequest($uri); $httpRequest->setPostData($request); $httpRequest->sendRequest(); return XML_RPC2_Backend_Php_Response::decode(simplexml_load_string($httpRequest->getBody())); } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Request.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Request.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Request.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 * @author Sergio Carvalho <sergio.carvalho@portugalmail.com> */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value.php'; /* }}} /* /** * XML_RPC request backend class. This class represents an XML_RPC request, exposing the methods * needed to encode/decode a request. * * @author Sergio Carvalho <sergio.carvalho@portugalmail.com> * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Request { /* Fields {{{ */ /** Name of requested method */ protected $_methodName = ''; /** Request parameters */ protected $_parameters = null; /* }}} */ /* setMethodName {{{ */ /** * methodName property setter * * @param mixed value The new methodName */ protected function setMethodName($value) { $this->_methodName = $value; } /* }}} */ /* getMethodName {{{ */ /** * methodName property getter * * @return mixed The current methodName */ public function getMethodName() { return $this->_methodName; } /* }}} */ /* setParameters {{{ */ /** * parameters property setter * * @param mixed value The new parameters */ public function setParameters($value) { $this->_parameters = $value; } /* }}} */ /* addParameter {{{ */ /** * parameters property appender * * @param mixed value The new parameter */ public function addParameter($value) { $this->_parameters[] = $value; } /* }}} */ /* getParameters {{{ */ /** * parameters property getter * * @return mixed The current parameters */ public function getParameters() { return $this->_parameters; } /* }}} */ /* constructor {{{ */ /** * Create a new xml-rpc request with the provided methodname * * @param string Name of method targeted by this xml-rpc request */ function __construct($methodName) { $this->setMethodName($methodName); $this->setParameters(array()); } /* }}} */ /* encode {{{ */ /** * Encode the request for transmission. * * @return string XML-encoded request (a full XML document) */ public function encode() { $methodName = $this->getMethodName(); $parameters = $this->getParameters(); $result = '<?xml version="1.0"?>'; $result .= '<methodCall>'; $result .= "<methodName>${methodName}</methodName>"; $result .= '<params>'; foreach($parameters as $parameter) { $result .= '<param><value>'; $result .= ($parameter instanceof XML_RPC2_Backend_Php_Value) ? $parameter->encode() : XML_RPC2_Backend_Php_Value::createFromNative($parameter)->encode(); $result .= '</value></param>'; } $result .= '</params>'; $result .= '</methodCall>'; return $result; } /* }}} */ /* createFromDecode {{{ */ /** * Decode a request from XML and construct a request object with the createFromDecoded values * * @param SimpleXMLElement The encoded XML-RPC request. * @return XML_RPC2_Backend_Php_Request The xml-rpc request, represented as an object instance */ public static function createFromDecode($simpleXML) { $methodName = (string) $simpleXML->methodName; $params = array(); foreach ($simpleXML->params->param as $param) { foreach ($param->value as $value) { $params[] = XML_RPC2_Backend_Php_Value::createFromDecode($value)->getNativeValue(); } } $result = new XML_RPC2_Backend_Php_Request($methodName); $result->setParameters($params); return $result; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Response.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Response.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Response.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value.php'; require_once 'XML/RPC2/Backend/Php/Value/Struct.php'; /* }}} /* /** * XML-RPC response backend class. * * This class represents an XML_RPC request, exposing the methods * needed to encode/decode an xml-rpc response. * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Response { /* encode {{{ */ /** * Encode a normal XML-RPC response, containing the provided value * * You may supply a php-native value, or an XML_RPC2_Backend_Php_Value instance, to be returned. Usually providing a native value * is more convenient. However, for some types, XML_RPC2_Backend_Php_Value::createFromNative can't properly choose the xml-rpc * type. In these cases, constructing an XML_RPC2_Backend_Php_Value and using it as param here is the only way to return the desired * type. * * @see http://www.xmlrpc.com/spec * @see XML_RPC2_Backend_Php_Value::createFromNative * @param mixed The result value which the response will envelop * @return string The XML payload */ public static function encode($param) { if (!$param instanceof XML_RPC2_Backend_Php_Value) { $param = XML_RPC2_Backend_Php_Value::createFromNative($param); } ob_start(); print('<?xml version="1.0"?>'); ?> <methodResponse><params><param><value><?= $param->encode() ?></value></param></params></methodResponse><?php $result = ob_get_contents(); ob_end_clean(); return $result; } /* }}} */ /* encodeFault {{{ */ /** * Encode a fault XML-RPC response, containing the provided code and message * * @see http://www.xmlrpc.com/spec * @param int Response code * @param string Response message * @return string The XML payload */ public static function encodeFault($code, $message) { $value = new XML_RPC2_Backend_Php_Value_Struct(array('faultCode' => (int) $code, 'faultString' => (string) $message)); ob_start(); print('<?xml version="1.0"?>'); ?> <methodResponse><fault><value><?= $value->encode() ?></value></fault></methodResponse><?php $result = ob_get_contents(); ob_end_clean(); return $result; } /* }}} */ /* decode {{{ */ /** * Parse a response and either return the native PHP result. * * This method receives an XML-RPC response document, in SimpleXML format, decodes it and returns the payload value. * * @param SimpleXmlElement The Transport XML * @return mixed The response payload * * @see http://www.xmlrpc.com/spec * @throws XML_RPC2_FaultException Signals the decoded response was an XML-RPC fault * @throws XML_RPC2_DecodeException Signals an ill formed payload response section */ public static function decode(SimpleXMLElement $xml) { $faultNode = $xml->xpath('/methodResponse/fault'); if (count($faultNode) == 1) { throw XML_RPC2_FaultException::createFromDecode($faultNode[0]); } $paramValueNode = $xml->xpath('/methodResponse/params/param/value'); if (count($paramValueNode) == 1) { return XML_RPC2_Backend_Php_Value::createFromDecode($paramValueNode[0])->getNativeValue(); } throw new XML_RPC2_DecodeException('Unable to decode xml-rpc response. No fault nor params/param elements found'); } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Server.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Server.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Server.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Backend/Php/Request.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; require_once 'XML/RPC2/Exception.php'; /* }}} */ /** * XML_RPC server class PHP-only backend. * * The XML_RPC2_Server does the work of decoding and encoding xml-rpc request and response. The actual * method execution is delegated to the call handler instance. * * The XML_RPC server is responsible for decoding the request and calling the appropriate method in the * call handler class. It then encodes the result into an XML-RPC response and returns it to the client. * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Server extends XML_RPC2_Server { /* Constructor {{{ */ /** * Create a new XML-RPC Server. * * The constructor receives only one parameter: the Call Handler. The call handler executes the actual * method call. XML_RPC2 server acts as a protocol decoder/encoder between the call handler and the client */ function __construct($callHandler) { parent::__construct($callHandler); } /* }}} */ /* errorToException {{{ */ public static function errorToException($errno, $errstr, $errfile, $errline) { switch ($errno) { case E_WARNING: case E_NOTICE: case E_USER_WARNING: case E_USER_NOTICE: case E_STRICT: // Silence warnings // TODO Logging should occur here break; default: throw new Exception('PHP error reported "' . $errstr . '" on ' . $errfile . ':' . $errline); } } /* }}} */ /* handleCall {{{ */ /** * Respond to the XML-RPC request. * * handleCall reads the XML-RPC request from the raw HTTP body and decodes it. It then calls the * corresponding method in the call handler class, returning the encoded result to the client. */ public function handleCall() { try { $oldErrorHandler = set_error_handler(array('XML_RPC2_Backend_Php_Server', 'errorToException')); $request = @simplexml_load_string($GLOBALS['HTTP_RAW_POST_DATA']); if (!is_object($request)) throw new XML_RPC2_FaultException('Unable to parse request XML', 0); $request = XML_RPC2_Backend_Php_Request::createFromDecode($request); $method = $request->getMethodName(); if (array_key_exists($method, $this->getAliases())) { $method = $this->_aliases[$method]; } $arguments = $request->getParameters(); print(XML_RPC2_Backend_Php_Response::encode(call_user_func_array(array($this->getCallHandler(), $method), $arguments))); if ($oldErrorHandler !== FALSE) set_error_handler($oldErrorHandler); } catch (XML_RPC2_FaultException $e) { print(XML_RPC2_Backend_Php_Response::encodeFault($e->getFaultCode(), $e->getMessage())); } catch (Exception $e) { print(XML_RPC2_Backend_Php_Response::encodeFault(1, 'Unhandled ' . get_class($e) . ' exception:' . $e->getMessage())); } } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Value.php'; /* }}} */ /** * XML_RPC value abstract class. All XML_RPC value classes inherit from XML_RPC2_Value * * @author Sérgio Carvalho * @package XML_RPC2 */ abstract class XML_RPC2_Backend_Php_Value extends XML_RPC2_Value { /* createFromNative {{{ */ /** * Choose a XML_RPC2_Value subclass appropriate for the * given value and create it. * * This method tries to find the most adequate XML-RPC datatype to hold * a given PHP native type. Note that distinguishing some datatypes may be * difficult: * - Timestamps are represented by PHP integers, so an XML_RPC2_Value_Datetime is never returned * - Indexed arrays and associative arrays are the same native PHP type. In this case: * a) The array's indexes start at 0 or 1 and increase monotonically with step 1, or * b) they do not * in the first case, an XML_RPC2_Value_Array is returned. In the second, a XML_RPC2_Value_Struct is returned. * - PHP Objects are serialized and represented in an XML_RPC2_Value_Base64 * * Whenever native object automatic detection proves inaccurate, use XML_RPC2_Value::createFromNative providing * a valid explicit type as second argument * * the appropriate XML_RPC2_Value child class instead. * * @param mixed The native value * @param string The xml-rpc target encoding type, as per the xmlrpc spec (optional) * @throws XML_RPC2_InvalidTypeEncodeException When the native value has a type that can't be translated to XML_RPC * @return A new XML_RPC2_Value instance * @see XML_RPC_Client::__call * @see XML_RPC_Server */ public static function createFromNative($nativeValue, $explicitType = null) { if (is_null($explicitType)) { switch (gettype($nativeValue)) { case 'boolean': $explicitType = 'boolean'; break; case 'integer': $explicitType = 'int'; break; case 'double': $explicitType = 'double'; break; case 'string': $explicitType = 'string'; break; case 'array': $explicitType = 'array'; $keys = array_keys($nativeValue); if (($keys[0] !== 0) && ($keys[0] !== 1)) $explicitType = 'struct'; $i=0; do { $previous = $keys[$i]; $i++; if (array_key_exists($i, $keys) && ($keys[$i] !== $keys[$i - 1] + 1)) $explicitType = 'struct'; } while (array_key_exists($i, $keys) && $explicitType == 'array'); break; case 'object': $nativeValue = serialize($nativeValue); $explicitType = 'base64'; break; case 'resource': case 'NULL': case 'unknown type': throw new XML_RPC2_InvalidTypeEncodeException(sprintf('Impossible to encode value \'%s\' from type \'%s\'. No analogous type in XML_RPC.', (string) $nativeValue, gettype($nativeValue))); default: throw new XML_RPC2_InvalidTypeEncodeException(sprintf('Unexpected PHP native type returned by gettype: \'%s\', for value \'%s\'', gettype($nativeValue), (string) $nativeValue)); } } $explicitType = ucfirst(strtolower($explicitType)); switch ($explicitType) { case 'I4': case 'Int': case 'Boolean': case 'Double': case 'String': require_once 'XML/RPC2/Backend/Php/Value/Scalar.php'; return XML_RPC2_Backend_Php_Value_Scalar::createFromNative($nativeValue); break; case 'Datetime.iso8601': require_once 'XML/RPC2/Backend/Php/Value/Datetime.php'; return new XML_RPC2_Backend_Php_Value_Datetime($nativeValue); break; case 'Base64': require_once 'XML/RPC2/Backend/Php/Value/Base64.php'; return new XML_RPC2_Backend_Php_Value_Base64($nativeValue); break; case 'Array': require_once 'XML/RPC2/Backend/Php/Value/Array.php'; return new XML_RPC2_Backend_Php_Value_Array($nativeValue); break; case 'Struct': require_once 'XML/RPC2/Backend/Php/Value/Struct.php'; return new XML_RPC2_Backend_Php_Value_Struct($nativeValue); break; default: throw new XML_RPC2_InvalidTypeEncodeException(sprintf('Unexpected explicit encoding type \'%s\'', $explicitType)); } } /* }}} */ /* createFromDecode {{{ */ /** * Decode an encoded value and build the applicable XML_RPC2_Value subclass * * @param SimpleXMLElement The encoded XML-RPC value, */ public static function createFromDecode($simpleXML) { // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when // xpath is used both in an element and in one of its children $simpleXML = simplexml_load_string($simpleXML->asXML()); $valueType = $simpleXML->xpath('./*'); if (count($valueType) == 1) { // Usually we must check the node name $nodename = dom_import_simplexml($valueType[0])->nodeName; switch ($nodename) { case 'i4': case 'int': $nativeType = 'Integer'; break; case 'boolean': $nativeType = 'Boolean'; break; case 'double': $nativeType = 'Double'; break; case 'string': $nativeType = 'String'; break; case 'dateTime.iso8601': $nativeType = 'Datetime'; break; case 'base64': $nativeType = 'Base64'; break; case 'array': $nativeType = 'Array'; break; case 'struct': $nativeType = 'Struct'; break; default: throw new XML_RPC2_DecodeException(sprintf('Unable to decode XML-RPC value. Value type is not recognized \'%s\'', $nodename)); } } elseif (count($valueType) == 0) { // Default type is string $nativeType = 'String'; } else { throw new XML_RPC2_DecodeException(sprintf('Unable to decode XML-RPC value. Value presented %s type nodes: %s.', count($valueType), $simpleXML->asXML())); } require_once(sprintf('XML/RPC2/Backend/Php/Value/%s.php', $nativeType)); $nativeType = 'XML_RPC2_Backend_Php_Value_' . $nativeType; return self::createFromNative(@call_user_func(array($nativeType, 'decode'), $simpleXML), $nodename); } /* }}} */ /* encode(abstract) {{{ */ /** * Encode the instance into XML, for transport * * @return string The encoded XML-RPC value, */ public abstract function encode(); /* }}} */ /* decode(abstract) {{{ */ /** * decode. Decode transport XML and set the instance value accordingly * * @param mixed The encoded XML-RPC value, */ public abstract static function decode($xml); /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Array.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Array.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Array.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value.php'; /* }}} */ /** * XML_RPC array value class. Represents values of type array * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Value_Array extends XML_RPC2_Backend_Php_Value { /* Fields {{{ */ /** The native value of this scalar instance */ /* setNativeValue {{{ */ /** * nativeValue property setter * * @param mixed value The new nativeValue */ protected function setNativeValue($value) { if (!is_array($value)) { throw new XML_RPC2_InvalidTypeException(sprintf('Cannot create XML_RPC2_Value_Array from type \'%s\'.', gettype($nativeValue))); } $this->_nativeValue = $value; } /* }}} */ /* getNativeValue {{{ */ /** * nativeValue property getter * * @return mixed The current nativeValue */ public function getNativeValue() { return $this->_nativeValue; } /* }}} */ protected $_nativeValue = null; /* }}} */ /* Constructor {{{ */ /** * Constructor. Will build a new XML_RPC2_Backend_Php_Value_Array with the given nativeValue * * @param mixed nativeValue */ public function __construct($nativeValue) { $this->setNativeValue($nativeValue); } /* }}} */ /* createFromDecode {{{ */ /** * Decode an encoded value and build the applicable XML_RPC2_Value subclass * * @param string The encoded XML-RPC value, */ public static function createFromDecode($encodedString) { } /* }}} */ /* encode {{{ */ /** * Encode the instance into XML, for transport * * @return string The encoded XML-RPC value, */ public function encode() { $result = '<array><data>'; foreach($this->getNativeValue() as $element) { $result .= '<value>'; $result .= ($element instanceof XML_RPC2_Backend_Php_Value) ? $element->encode() : XML_RPC2_Backend_Php_Value::createFromNative($element)->encode(); $result .= '</value>'; } $result .= '</data></array>'; return $result; } /* }}} */ /* decode {{{ */ /** * decode. Decode transport XML and set the instance value accordingly * * @param mixed The encoded XML-RPC value, */ public static function decode($xml) { // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when // xpath is used both in an element and in one of its children $xml = simplexml_load_string($xml->asXML()); $values = $xml->xpath('/value/array/data/value'); $result = array(); foreach (array_keys($values) as $i) { $result[] = XML_RPC2_Backend_Php_Value::createFromDecode($values[$i])->getNativeValue(); } return $result; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Base64.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Base64.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Base64.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value/Scalar.php'; /* }}} */ /** * XML_RPC base64 value class. Instances of this class represent base64-encoded string scalars in XML_RPC * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Value_Base64 extends XML_RPC2_Backend_Php_Value_Scalar { /* Constructor {{{ */ /** * Constructor. Will build a new XML_RPC2_Backend_Php_Value_Base64 with the given value * * This class handles encoding-decoding internally. Do not provide the * native string base64-encoded * * @param mixed String to be transmited base64-encoded */ public function __construct($nativeValue) { $this->setScalarType('base64'); $this->setNativeValue($nativeValue); } /* }}} */ /* encode {{{ */ /** * Encode the instance into XML, for transport * * @return string The encoded XML-RPC value, */ public function encode() { return '<' . $this->getScalarType() . '>' . base64_encode($this->getNativeValue()) . '</' . $this->getScalarType() . '>'; } /* }}} */ /* decode {{{ */ /** * decode. Decode transport XML and set the instance value accordingly * * @param mixed The encoded XML-RPC value, */ public static function decode($xml) { // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when // xpath is used both in an element and in one of its children $xml = simplexml_load_string($xml->asXML()); $value = $xml->xpath('/value/base64/text()'); if (!array_key_exists(0, $value)) { $value = $xml->xpath('/value/text()'); } return base64_decode($value[0]); } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Boolean.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Boolean.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Boolean.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value/Scalar.php'; /* }}} */ /** * XML_RPC boolean value class. Instances of this class represent boolean scalars in XML_RPC * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Value_Boolean extends XML_RPC2_Backend_Php_Value_Scalar { /* Constructor {{{ */ /** * Constructor. Will build a new XML_RPC2_Value_Boolean with the given value * * @param mixed value */ public function __construct($nativeValue) { parent::__construct('boolean', $nativeValue); } /* }}} */ /* encode {{{ */ /** * Encode the instance into XML, for transport * * @return string The encoded XML-RPC value, */ public function encode() { return '<' . $this->getScalarType() . '>' . ($this->getNativeValue() ? 1 : 0). '</' . $this->getScalarType() . '>'; } /* }}} */ /* decode {{{ */ /** * decode. Decode transport XML and set the instance value accordingly * * @param mixed The encoded XML-RPC value, */ public static function decode($xml) { // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when // xpath is used both in an element and in one of its children $xml = simplexml_load_string($xml->asXML()); $value = $xml->xpath('/value/boolean/text()'); return (boolean) $value[0]; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Datetime.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Datetime.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Datetime.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value/Scalar.php'; /* }}} */ /** * XML_RPC datetime value class. Instances of this class represent datetime scalars in XML_RPC * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Value_Datetime extends XML_RPC2_Backend_Php_Value_Scalar { /* Constructor {{{ */ /** * Constructor. Will build a new XML_RPC2_Backend_Php_Value_Datetime with the given value * * The provided value can be an int, which will be interpreted as a Unix timestamp, or * a string in iso8601 format * * @param mixed value * @see http://www.w3.org/TR/NOTE-datetime */ public function __construct($nativeValue) { $this->setScalarType('dateTime.iso8601'); if (gettype($nativeValue) == 'string') { if (!preg_match('/([0-9]{4})(-?([0-9]{2})(-?([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?/', $nativeValue, $matches)) { throw new XML_RPC2_InvalidDateFormatException(sprintf('Provided date \'%s\' is not ISO-8601.', $nativeValue)); } else { $year = $matches[1]; $month = array_key_exists(3, $matches) ? $matches[3] : 1; $day = array_key_exists(5, $matches) ? $matches[5] : 1; $hour = array_key_exists(7, $matches) ? $matches[7] : 0; $minutes = array_key_exists(8, $matches) ? $matches[8] : 0; $seconds = array_key_exists(10, $matches) ? $matches[10] : 0; $milliseconds = array_key_exists(12, $matches) ? ((double) ('0.' . $matches[12])) : 0; $tzSeconds = array_key_exists(13, $matches) ? ($matches[13] == 'Z' ? 0 : ($matches[15] == '-' ? -1 : 1) * (((int) $matches[16]) * 3600 + ((int) $matches[17]) * 60)) : 0; $this->setNativeValue( ((double) @gmmktime($hour, $minutes, $seconds, $month, $day, $year, 0)) + ((double) $milliseconds) - ((double) $tzSeconds)); } } else { $this->setNativeValue($nativeValue); } } /* }}} */ /* decode {{{ */ /** * decode. Decode transport XML and set the instance value accordingly * * @param mixed The encoded XML-RPC value, */ public static function decode($xml) { // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when // xpath is used both in an element and in one of its children $xml = simplexml_load_string($xml->asXML()); $value = $xml->xpath('/value/dateTime.iso8601/text()'); if (!array_key_exists(0, $value)) { $value = $xml->xpath('/value/text()'); } return (string) $value[0]; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Double.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Double.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Double.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value/Scalar.php'; /* }}} */ /** * XML_RPC double value class. Instances of this class represent int scalars in XML_RPC * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Value_Double extends XML_RPC2_Backend_Php_Value_Scalar { /* Constructor {{{ */ /** * Constructor. Will build a new XML_RPC2_Backend_Php_Value_Double with the given value * * @param mixed value */ public function __construct($nativeValue) { $this->setScalarType('double'); $this->setNativeValue($nativeValue); } /* }}} */ /* decode {{{ */ /** * decode. Decode transport XML and set the instance value accordingly * * @param mixed The encoded XML-RPC value, */ public static function decode($xml) { // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when // xpath is used both in an element and in one of its children $xml = simplexml_load_string($xml->asXML()); $value = $xml->xpath('/value/double/text()'); return (double) $value[0]; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Integer.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Integer.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Integer.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value/Scalar.php'; /* }}} */ /** * XML_RPC integer value class. Instances of this class represent int scalars in XML_RPC * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Value_Integer extends XML_RPC2_Backend_Php_Value_Scalar { /* Constructor {{{ */ /** * Constructor. Will build a new XML_RPC2_Backend_Php_Value_Integer with the given value * * @param mixed value */ public function __construct($nativeValue) { $this->setScalarType('int'); $this->setNativeValue($nativeValue); } /* }}} */ /* decode {{{ */ /** * decode. Decode transport XML and set the instance value accordingly * * @param mixed The decoded XML-RPC value, */ public static function decode($xml) { // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when // xpath is used both in an element and in one of its children $xml = simplexml_load_string($xml->asXML()); $value = $xml->xpath('/value/int/text()|/value/i4/text()'); return (int) $value[0]; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Scalar.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Scalar.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Scalar.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value.php'; /* }}} */ /** * XML_RPC scalar value abstract class. All XML_RPC value classes representing scalar types inherit from XML_RPC2_Value_Scalar * * @author Sérgio Carvalho * @package XML_RPC2 */ abstract class XML_RPC2_Backend_Php_Value_Scalar extends XML_RPC2_Backend_Php_Value { /* Fields {{{ */ /** The native type of this scalar instance as per XML_RPC spec */ /* setScalarType {{{ */ /** * scalarType property setter * * @param mixed value The new scalarType */ protected function setScalarType($value) { switch ($value) { case 'int': case 'i4': case 'boolean': case 'string': case 'double': case 'dateTime.iso8601': case 'base64': $this->_scalarType = $value; break; default: throw new XML_RPC2_InvalidTypeException(sprintf('Type \'%s\' is not an XML-RPC scalar type', $value)); } } /* }}} */ /* getScalarType {{{ */ /** * scalarType property getter * * @return mixed The current scalarType */ public function getScalarType() { return $this->_scalarType; } /* }}} */ protected $_scalarType = null; /** The native value of this scalar instance */ /* setNativeValue {{{ */ /** * nativeValue property setter * * @param mixed value The new nativeValue */ protected function setNativeValue($value) { $this->_nativeValue = $value; } /* }}} */ /* getNativeValue {{{ */ /** * nativeValue property getter * * @return mixed The current nativeValue */ public function getNativeValue() { return $this->_nativeValue; } /* }}} */ protected $_nativeValue = null; /* }}} */ /* Constructor {{{ */ /** * Constructor. Will build a new XML_RPC2_Value_Scalar with the given nativeValue * * @param mixed nativeValue */ public function __construct($scalarType, $nativeValue) { $this->setScalarType($scalarType); $this->setNativeValue($nativeValue); } /* }}} */ /* createFromNative {{{ */ /** * Choose a XML_RPC2_Value subclass appropriate for the * given value and create it. * * @param string The native value * @param string Optinally, the scalar type to use * @throws XML_RPC2_InvalidTypeEncodeException When native value's type is not a native type * @return XML_RPC2_Value The newly created value */ public static function createFromNative($nativeValue, $explicitType = null) { if (is_null($explicitType)) { switch (gettype($nativeValue)) { case 'boolean': case 'integer': case 'double': case 'string': $explicitType = gettype($nativeValue); break; default: throw new XML_RPC2_InvalidTypeEncodeException(sprintf('Impossible to encode scalar value \'%s\' from type \'%s\'. Native type is not a scalar XML_RPC type (boolean, integer, double, string)', (string) $nativeValue, gettype($nativeValue))); } } $explicitType = ucfirst(strtolower($explicitType)); require_once(sprintf('XML/RPC2/Backend/Php/Value/%s.php', $explicitType)); $explicitType = sprintf('XML_RPC2_Backend_Php_Value_%s', $explicitType); return new $explicitType($nativeValue); } /* }}} */ /* encode {{{ */ /** * Encode the instance into XML, for transport * * @return string The encoded XML-RPC value, */ public function encode() { return '<' . $this->getScalarType() . '>' . $this->getNativeValue() . '</' . $this->getScalarType() . '>'; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value/String.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value/String.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value/String.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value/Scalar.php'; /* }}} */ /** * XML_RPC string value class. Instances of this class represent string scalars in XML_RPC * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Value_String extends XML_RPC2_Backend_Php_Value_Scalar { /* Constructor {{{ */ /** * Constructor. Will build a new XML_RPC2_Backend_Php_Value_String with the given value * * @param mixed value */ public function __construct($nativeValue) { $this->setScalarType('string'); $this->setNativeValue($nativeValue); } /* }}} */ /* encode {{{ */ /** * Encode the instance into XML, for transport * * @return string The encoded XML-RPC value, */ public function encode() { return '<' . $this->getScalarType() . '>' . strtr($this->getNativeValue(),array('&' => '&', '<' => '<' , '>' => '>')) . '</' . $this->getScalarType() . '>'; } /* }}} */ /* decode {{{ */ /** * decode. Decode transport XML and set the instance value accordingly * * @param mixed The encoded XML-RPC value, */ public static function decode($xml) { // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when // xpath is used both in an element and in one of its children $xml = simplexml_load_string($xml->asXML()); $value = $xml->xpath('/value/string/text()'); if (!array_key_exists(0, $value)) { $value = $xml->xpath('/value/text()'); } return (string) $value[0]; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Struct.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Struct.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Struct.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value.php'; /* }}} */ /** * XML_RPC struct value class. Represents values of type struct (associative struct) * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Value_Struct extends XML_RPC2_Backend_Php_Value { /* Fields {{{ */ /** The native value of this scalar instance */ /* setNativeValue {{{ */ /** * nativeValue property setter * * @param mixed value The new nativeValue */ protected function setNativeValue($value) { if (!is_array($value)) { throw new XML_RPC2_InvalidTypeException(sprintf('Cannot create XML_RPC2_Backend_Php_Value_Struct from type \'%s\'.', gettype($nativeValue))); } $this->_nativeValue = $value; } /* }}} */ /* getNativeValue {{{ */ /** * nativeValue property getter * * @return mixed The current nativeValue */ public function getNativeValue() { return $this->_nativeValue; } /* }}} */ protected $_nativeValue = null; /* }}} */ /* Constructor {{{ */ /** * Constructor. Will build a new XML_RPC2_Backend_Php_Value_Scalar with the given nativeValue * * @param mixed nativeValue */ public function __construct($nativeValue) { $this->setNativeValue($nativeValue); } /* }}} */ /* encode {{{ */ /** * Encode the instance into XML, for transport * * @return string The encoded XML-RPC value, */ public function encode() { $result = '<struct>'; foreach($this->getNativeValue() as $name => $element) { $result .= '<member>'; $result .= '<name>'; $result .= strtr($name, array('&' => '&', '<' => '<', '>' => '>')); $result .= '</name>'; $result .= '<value>'; $result .= ($element instanceof XML_RPC2_Backend_Php_Value) ? $element->encode() : XML_RPC2_Backend_Php_Value::createFromNative($element)->encode(); $result .= '</value>'; $result .= '</member>'; } $result .= '</struct>'; return $result; } /* }}} */ /* decode {{{ */ /** * decode. Decode transport XML and set the instance value accordingly * * @param mixed The encoded XML-RPC value, */ public static function decode($xml) { // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when // xpath is used both in an element and in one of its children $xml = simplexml_load_string($xml->asXML()); $values = $xml->xpath('/value/struct/member'); $result = array(); foreach (array_keys($values) as $i) { $result[(string) $values[$i]->name] = XML_RPC2_Backend_Php_Value::createFromDecode($values[$i]->value)->getNativeValue(); } return $result; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext/Client.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext/Client.php +++ pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext/Client.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Value.php'; require_once 'XML/RPC2/Client.php'; require_once 'XML/RPC2/Backend/Php/Request.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; require_once 'XML/RPC2/Util/HTTPRequest.php'; /* }}} /* /** * XML_RPC client backend class. This backend class uses the XMLRPCext extension to execute the call. * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Xmlrpcext_Client extends XML_RPC2_Client { /* constructor {{{ */ /** * Construct a new XML_RPC2_Client PHP Backend. * * To create a new XML_RPC2_Client, a URI must be provided (e.g. http://xmlrpc.example.com/1.0/). * Optionally, a prefix may be set, wich will be prepended to method names, before calling. * Prefixes are extremely useful namely when method names contain a period '.' turning them invalid * under PHP syntax. * * @param string URI for the XML-RPC server * @param string (optional) Prefix to prepend on all called functions * @param string (optional) Proxy server URI * */ function __construct($uri, $prefix = '', $proxy = null) { parent::__construct($uri, $prefix, $proxy); } /* }}} */ /* remoteCall {{{ */ /** * remoteCall executes the XML-RPC call, and returns the result * * @param string Method name * @param array Parameters */ public function remoteCall($methodName, $parameters) { $request = xmlrpc_encode_request($this->getPrefix() . $methodName, $parameters); $uri = $this->getUri(); $httpRequest = new XML_RPC2_Util_HTTPRequest($uri); $httpRequest->setPostData($request); $httpRequest->sendRequest(); $result = xmlrpc_decode($httpRequest->getBody()); if ($result === false) { throw new XML_RPC2_Exception('Unable to decode response'); } if (xmlrpc_is_fault($result)) { throw new XML_RPC2_FaultException($result['faultString'], $result['faultCode']); } return $result; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext/Server.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext/Server.php +++ pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext/Server.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Backend/Php/Request.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; require_once 'XML/RPC2/Exception.php'; /* }}} */ /** * XML_RPC server class XMLRPCext extension-based backend * * The XML_RPC2_Server does the work of decoding and encoding xml-rpc request and response. The actual * method execution is delegated to the call handler instance. * * The XML_RPC server is responsible for decoding the request and calling the appropriate method in the * call handler class. It then encodes the result into an XML-RPC response and returns it to the client. * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Xmlrpcext_Server extends XML_RPC2_Server { /* _xmlrpcextServer Field {{{ */ private $_xmlrpcextServer; /** _xmlrpcextServer getter * * @return resource xmlrpcext server */ private function getXmlrpcextServer() { return $this->_xmlrpcextServer; } /** _xmlrpcextServer setter * * @param resource xmlrpcext server */ private function setXmlrpcextServer($server) { $this->_xmlrpcextServer = $server; } /* }}} */ /* Constructor {{{ */ /** * Create a new XML-RPC Server. * * The constructor receives only one parameter: the Call Handler. The call handler executes the actual * method call. XML_RPC2 server acts as a protocol decoder/encoder between the call handler and the client */ function __construct($callHandler) { parent::__construct($callHandler); $this->setXmlrpcextServer(xmlrpc_server_create()); foreach ($callHandler->getMethods() as $method) { if (xmlrpc_server_register_method($this->getXmlrpcextServer(), $method->getName(), array($this, 'epiFunctionHandlerAdapter')) !== true) { throw new XML_RPC2_Exception('Unable to setup XMLRPCext server. xmlrpc_server_register_method returned non-true.'); } } } /* }}} */ /* epiFunctionHandlerAdapter {{{ */ /** * This is an adapter between XML_RPC2_CallHandler::__call and xmlrpc_server_register_method callback interface * * @param string Method name * @param array Parameters * @param array Application data (ignored) */ protected function epiFunctionHandlerAdapter($method_name, $params, $app_data) { return @call_user_func_array(array($this->getCallHandler(), $method_name), $params); } /* }}} */ /* errorToException {{{ */ public static function errorToException($errno, $errstr, $errfile, $errline) { switch ($errno) { case E_WARNING: case E_NOTICE: case E_USER_WARNING: case E_USER_NOTICE: case E_STRICT: // Silence warnings // TODO Logging should occur here break; default: throw new Exception('Classic error reported "' . $errstr . '" on ' . $errfile . ':' . $errline); } } /* }}} */ /* handleCall {{{ */ /** * Respond to the XML-RPC request. * * handleCall reads the XML-RPC request from the raw HTTP body and decodes it. It then calls the * corresponding method in the call handler class, returning the encoded result to the client. */ public function handleCall() { try { $oldErrorHandler = set_error_handler(array('XML_RPC2_Backend_Xmlrpcext_Server', 'errorToException')); $response = @xmlrpc_server_call_method($this->getXmlrpcextServer(), $GLOBALS['HTTP_RAW_POST_DATA'], null, array('output_type' => 'xml')); header('Content-type: text/xml'); header('Content-length: '.strlen($response)); print $response; if ($oldErrorHandler !== FALSE) set_error_handler($oldErrorHandler); } catch (XML_RPC2_FaultException $e) { print(XML_RPC2_Backend_Php_Response::encodeFault($e->getFaultCode(), $e->getMessage())); } catch (Exception $e) { print(XML_RPC2_Backend_Php_Response::encodeFault(1, 'Unhandled ' . get_class($e) . ' exception:' . $e->getMessage())); } } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext/Value.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext/Value.php +++ pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext/Value.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend.php'; /* }}} */ /** * XML_RPC value class for the XMLRPCext backend. * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Xmlrpcext_Value { /* createFromNative {{{ */ /** * Factory method that constructs the appropriate XML-RPC encoded type value * * @param mixed Value to be encode * @param string Explicit XML-RPC type as enumerated in the XML-RPC spec (defaults to automatically selected type) * @return mixed The encoded value */ public static function createFromNative($value, $explicitType) { if (!xmlrpc_set_type($value, $explicitType)) { throw new XML_RPC2_Exception('Error returned from xmlrpc_set_type'); } return $value; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Server/CallHandler.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Server/CallHandler.php +++ pear/XML_RPC2/XML/RPC2/Server/CallHandler.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; /* }}} */ /** * A CallHandler is responsible for actually calling the server-exported methods from the exported class. * * This class is abstract and not meant to be used directly by XML_RPC2 users. * * XML_RPC2_Server_CallHandler provides the basic code for a call handler class. An XML_RPC2 Call Handler * operates in tandem with an XML_RPC2 server to export a classe's methods. While XML_RPC2 Server * is responsible for request decoding and response encoding, the Call Handler is responsible for * delegating the actual method call to the intended target. * * Different server behaviours can be obtained by plugging different Call Handlers into the XML_RPC2_Server. * Namely, there are two call handlers available: * - XML_RPC2_Server_Callhandler_Class: Which exports a classe's public static methods * - XML_RPC2_Server_Callhandler_Instance: Which exports an object's pubilc methods * * @see XML_RPC2_Server_Callhandler_Class * @see XML_RPC2_Server_Callhandler_Instance * * @package XML_RPC2 * @author Sérgio Carvalho <sergio.carvalho@portugalmail.com> */ abstract class XML_RPC2_Server_CallHandler { /* methods Field {{{ */ /** Holds server methods */ protected $_methods = array(); /** * methods setter * * @param array Array of XML_RPC2_Server_Method instances */ protected function setMethods($methods) { $this->_methods = $methods; } /** * methods getter * * @return array Array of XML_RPC2_Server_Method instances */ public function getMethods() { return $this->_methods; } /** * method appender * * @param XML_RPC2_Server_Method Method to append to _methods */ protected function addMethod(XML_RPC2_Server_Method $method) { $this->_methods[$method->getName()] = $method; } /** * method getter * * @param string Name of method to return * @param XML_RPC2_Server_Method Method named $name */ public function getMethod($name) { return $this->_methods[$name]; } /* }}} */ /* system_listMethods {{{ */ /** * Introspect server, returning method list. * * This method may be used to * enumerate the methods implemented by the XML-RPC server. The * system.listMethods method requires no parameters. It returns an array * of strings, each of which is the name of a method implemented by the * server. * * @returns array method names * */ protected static final function system_listMethods() { return array_keys($this->getMethods()); } /* }}} */ /* system_methodHelp {{{ */ /** * Introspect server, returning method help text. * * If the method does * not exist, returns false. If the method exists, but help text is * not defined, returns an empty string. * * @param string Method name whose help to return * @returns string Method help * */ protected static final function system_methodHelp($methodName) { $methods = $this->getMethods(); if (!array_key_exists($methodName, $methods)) { return false; } return $methods[$methodName]->methodHelp(); } /* }}} */ /* system_methodSignature {{{ */ /** * Introspect server, returning a method signature. * * This method takes one * parameter, the name of a method implemented by the XML-RPC server. * It returns an array of possible signatures for this method. A signature * is an array of types. The first of these types is the return type of * the method, the rest are parameters. * Even if the XML-RPC spec supports function overloading, PHP does not. * On this server, this function will either return a one-element array or * false (if the method does not exist). * * @param string Method name whose signature to return * @returns string Method help * * @xmlrpc.prefix system. * */ protected static final function system_methodSignature($methodName) { $methods = $this->getMethods(); if (!array_key_exists($methodName, $methods)) { return false; } return array($methods[$methodName]->methodSignature()); } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Server/Method.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Server/Method.php +++ pear/XML_RPC2/XML/RPC2/Server/Method.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * XML_RPC2_Server_Method * * @package XML_RPC2 * @author Sergio Carvalho <sergio.carvalho@portugalmail.com> **/ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; /* }}} */ /** * Class representing an XML-RPC exported method. * * This class is used internally by XML_RPC2_Server. External users of the * package should not need to ever instantiate XML_RPC2_Server_Method * * @package XML_RPC2 * @author Sergio Carvalho <sergio.carvalho@portugalmail.com> * @see XML_RPC2_ServerMethodHandler **/ class XML_RPC2_Server_Method { /* fields {{{ */ /** Method signature parameters */ public $parameters; /** Method signature return type */ public $returns ; /** Method help, for introspection */ public $help; /* }}} */ /* internalMethod field {{{ */ /** Method name in PHP-land */ protected $_internalMethod; /** internalMethod getter * * @return string internalMethod */ public function getInternalMethod() { return $this->_internalMethod; } /** internalMethod setter * * @param string internalMethod */ public function setInternalMethod($value) { $this->_internalMethod = $value; } /* }}} */ /* hidden field {{{ */ /** True if the method is hidden */ protected $_hidden; /** hidden getter * * @return boolean hidden value */ public function isHidden() { return $this->_hidden; } /** hidden setter * * @param boolean hidden value */ public function setHidden($hidden) { $this->_hidden = $hidden; } /* }}} */ /* name Field {{{ */ /** External method name */ protected $_name; /** * _name getter * * @return string _name */ public function getName() { return $this->_name; } /** * _name setter * * @param string _name */ public function setName($name) { $this->_name = $name; } /* }}} */ /* constructor {{{ */ /** * Create a new XML-RPC method by introspecting a PHP method * * @param ReflectionMethod The PHP method to introspect */ public function __construct(ReflectionMethod $method, $defaultPrefix) { $hidden = false; $docs = $method->getDocComment(); if (!$docs) { $hidden = true; } $docs = explode("\n", $docs); $parameters = array(); $methodname = null; $returns = 'mixed'; $shortdesc = ''; $paramcount = -1; $prefix = $defaultPrefix; // Extract info from Docblock $paramDocs = array(); foreach ($docs as $i => $doc) { $doc = trim($doc, " \r\t/*"); if (strlen($doc) && strpos($doc, '@') !== 0) { if ($shortdesc) { $shortdesc .= "\n"; } $shortdesc .= $doc; continue; } if (strpos($doc, '@xmlrpc.hidden') === 0) { $hidden = true; } if ((strpos($doc, '@xmlrpc.prefix') === 0) && preg_match('/@xmlrpc.prefix( )*(.*)/', $doc, $matches)) { $prefix = $matches[2]; } if ((strpos($doc, '@xmlrpc.methodname') === 0) && preg_match('/@xmlrpc.prefix( )*(.*)/', $doc, $matches)) { $methodname = $matches[2]; } if (strpos($doc, '@param') === 0) { // Save doctag for usage later when filling parameters $paramDocs[] = $doc; } if (strpos($doc, '@return') === 0) { $param = preg_split("/\s+/", $doc); if (isset($param[1])) { $param = $param[1]; $returns = $param; } } } // Fill in info for each method parameter foreach ($method->getParameters() as $parameterIndex => $parameter) { // Parameter defaults $newParameter = array('optional' => false, 'type' => 'mixed'); // Attempt to extract type and doc from docblock if (array_key_exists($parameterIndex, $paramDocs) && preg_match('/@param\s+(\S+)(\s+(.+))/', $paramDocs[$parameterIndex], $matches)) { if (strpos($matches[1], '|')) { $newParameter['type'] = explode('|', $matches[1]); } else { $newParameter['type'] = $matches[1]; } $newParameter['doc'] = $matches[2]; } // Attempt to extract optional status from Reflection API if (method_exists($method, 'isOptional')) { $newParameter['optional'] = $parameter->isOptional(); } // Attempt to extract type from Reflection API if ($parameter->getClass()) { $newParameter['type'] = $parameter->getClass(); } $parameters[$parameter->getName()] = $newParameter; } if (is_null($methodname)) { $methodname = $prefix . $method->getName(); } $this->setInternalMethod($method->getName()); $this->parameters = $parameters; $this->returns = $returns; $this->help = $shortdesc; $this->setName($methodname); $this->setHidden($hidden); } /* }}} */ /* matchesSignature {{{ */ /** * Check if method matches provided call signature * * Compare the provided call signature with this methods' signature and * return true iff they match. * * @param string Signature to compare method name * @param array Array of parameter values for method call. * @return boolean True if call matches signature, false otherwise */ public function matchesSignature($methodName, $callParams) { if ($methodName != $this->getName()) return false; $paramIndex = 0; foreach($this->parameters as $param) { if (!($param['optional'] || array_key_exists($paramIndex, $callParams))) { // Missing non-optional param return false; } if ((array_key_exists($paramIndex, $callParams)) && (!($param['type'] == 'mixed' || $param['type'] == gettype($callParams[$paramIndex])))) { return false; } } return true; } /* }}} */ /* autoDocument {{{ */ /** * Return HTML snippet documenting method, for XML-RPC server introspection. * * @return string HTML snippet documenting method */ public function autoDocument() { $result = '<dl><dt>Method description</dt><dd>' . $this->help . '</dd>'; $result .= '<dt>Method parameters</dt><dd><dl>'; foreach ($this->parameters as $paramName => $param) { $result .= '<dt><i>' . $param['type'] . "</i>$paramName</dt><dd>"; if ($param['optional']) $result .= '[optional]'; $result .= $param['doc']; $result .= '</dd>'; } $result .= '</dl></dd>'; $result .= '<dt>Returns</dt><dd><i>' . $this->returns . '</i></dd>'; $result .= '</dl>'; return $result; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Server/CallHandler/Class.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Server/CallHandler/Class.php +++ pear/XML_RPC2/XML/RPC2/Server/CallHandler/Class.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Server/Method.php'; require_once 'XML/RPC2/Server/CallHandler.php'; /* }}} */ /** * This class is a server call handler which exposes a classe's static public methods. * * XML_RPC2_Server_Callhandler_Class is the preferred call handler to use when you are * designing your XML-RPC server from the ground up. Usage is quite simple: * - Create a class holding all of the XML-RPC server's exported procedures as public static methods (the interface class). * - PhpDoc the classes' methods, including at least method signature (params and return types) and short description. * - Use the XML_RPC2 factory method to create a server based on the interface class. * A simple example: * <code> * /** * * echoecho echoes the message received * * * * @param string Message * * @return string The echo * {@*} * class EchoServer { * public static function echoecho($string) * { * return $string; * } * } * * require_once 'XML/RPC2/Server.php'; * $server = XML_RPC2_Server::create('EchoServer'); * $server->handleCall(); * </code> * * Use this call handler if you have designed your xml-rpc external interface as a set of * public class methods on a given class. If, on the other hand, you intend to export an * already existing class, it may be that not all of the methods you want to export are static. * In that case, it is probably best to use XML_RPC2_Server_Callhandler_Instance instead. * * @see XML_RPC2_Server::create * @see XML_RPC2_Server_Callhandler_Instance * * @package XML_RPC2 * @author Sérgio Carvalho <sergio.carvalho@portugalmail.com> */ class XML_RPC2_Server_Callhandler_Class extends XML_RPC2_Server_CallHandler { /* className field {{{ */ /** name of target class */ private $_className; /** * className setter * * @param string Class name */ public function setClassName($className) { $this->_className = $className; } /** * className getter * * @return string Class name */ public function getClassName() { return $this->_className; } /* }}} */ /* constructor {{{ */ /** * XML_RPC2_Server_Callhandler_Class Constructor. Creates a new call handler exporting the give static class' methods * * Before using this constructor, take a look at XML_RPC2_Server::create. The factory * method is usually a quicker way of instantiating the server and its call handler. * * @see XML_RPC2_Server::create() * @param string The Target class. Calls will be made on this class * @param string Default prefix to prepend to all exported methods (defaults to '') */ public function __construct($className, $defaultPrefix) { $this->setClassname($className); $reflection = new ReflectionClass($className); foreach ($reflection->getMethods() as $method) { if ($method->isStatic() && $method->isPublic() && !$method->isAbstract() && !$method->isConstructor()) { $candidate = new XML_RPC2_Server_Method($method, $defaultPrefix); if (!$candidate->isHidden()) $this->addMethod($candidate); } } } /* }}} */ /* __call {{{ */ /** * __call catchall. Delegate the method call to the target class, and return its result * * @param string Name of method to call * @param array Array of parameters for call * @return mixed Whatever the target method returned */ public function __call($methodName, $parameters) { if (!array_key_exists($methodName, $this->getMethods())) { throw new XML_RPC2_UnknownMethodException("Method $methodName is not exported by this server"); } return call_user_func_array(array($this->getClassname(), $this->getMethod($methodName)->getInternalMethod()), $parameters); } /* }}} */ } /* */ ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Server/CallHandler/Instance.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Server/CallHandler/Instance.php +++ pear/XML_RPC2/XML/RPC2/Server/CallHandler/Instance.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Server/Method.php'; require_once 'XML/RPC2/Server/CallHandler.php'; /* }}} */ /** * This class is a server call handler which exposes an instance's public methods. * * XML_RPC2_Server_Callhandler_Instance is the preferred call handler to use when * you just need to quickly expose an already existing object. If designing a remote * API from the ground up, it's best to use XML_RPC2_Server_Callhandler_Class instead. * * Usage is simple: * - PhpDoc the methods, including at least method signature (params and return types) and short description. * - Use the XML_RPC2 factory method to create a server based on the interface class. * A simple example: * <code> * class EchoServer { * /** * * Echo the message * * * * @param string The string to echo * * @return string The echo * {@*} * public function echoecho($string) * { * return $string; * } * } * * require_once 'XML/RPC2/Server.php'; * $someInstance = new EchoServer(); * $server = XML_RPC2_Server::create($someInstance); * $server->handleCall(); * </code> * * @see XML_RPC2_Server::create * @see XML_RPC2_Server_Callhandler_Class * * @package XML_RPC2 * @author Sérgio Carvalho <sergio.carvalho@portugalmail.com> */ class XML_RPC2_Server_Callhandler_Instance extends XML_RPC2_Server_CallHandler { /* instance field {{{ */ /** instance of target object */ private $_instance; /** * instance setter * * @param object target object instance */ public function setInstance($instance) { $this->_instance = $instance; } /** * instance getter * * @return object target object instance */ public function getInstance() { return $this->_instance; } /* }}} */ /* constructor {{{ */ /** * XML_RPC2_Server_Callhandler_Class Constructor. Creates a new call handler exporting the given object methods * * Before using this constructor, take a look at XML_RPC2_Server::create. The factory * method is usually a quicker way of instantiating the server and its call handler. * * @see XML_RPC2_Server::create() * @param object The Target object. Calls will be made on this instance * @param string Default prefix to prepend to all exported methods (defaults to '') */ public function __construct($instance, $defaultPrefix) { $this->setInstance($instance); $reflection = new ReflectionClass(get_class($instance)); foreach ($reflection->getMethods() as $method) { if (!$method->isStatic() && $method->isPublic() && !$method->isConstructor()) { $candidate = new XML_RPC2_Server_Method($method, $defaultPrefix); if (!$candidate->isHidden()) $this->addMethod($candidate); } } } /* }}} */ /* __call {{{ */ /** * __call catchall. Delegate the method call to the target object, and return its result * * @param string Name of method to call * @param array Array of parameters for call * @return mixed Whatever the target method returned */ public function __call($methodName, $parameters) { if (!array_key_exists($methodName, $this->getMethods())) { throw new XML_RPC2_UnknownMethodException("Method $methodName is not exported by this server"); } return call_user_func_array(array($this->getInstance(), $this->getMethod($methodName)->getInternalMethod()), $parameters); } /* }}} */ } /* */ ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Util/HTTPRequest.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Util/HTTPRequest.php +++ pear/XML_RPC2/XML/RPC2/Util/HTTPRequest.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; /* }}} /* /** * XML_RPC utility HTTP request class. This class mimics a subset of PEAR's HTTP_Request * and is to be refactored out of the package once HTTP_Request releases an E_STRICT version. * * @package XML_RPC2 * @author Sérgio Carvalho */ class XML_RPC2_Util_HTTPRequest { /* body Field {{{ */ private $_body; /** * body field getter * * @return string body value */ public function getBody() { return $this->_body; } /** * body field setter * * @param string body value */ public function setBody($value) { $this->_body = $value; } /* }}} */ /* postData Field {{{ */ private $_postData; /** * postData field getter * * @return string postData value */ public function getPostData() { return $this->_postData; } /** * postData field setter * * @param string postData value */ public function setPostData($value) { $this->_postData = $value; } /* }}} */ /* method Field {{{ */ private $_method = 'POST'; /** * method field getter * * @return array method value */ public function getMethod() { return $this->_method; } /** * method field setter (ignored!) * * This setter is ignored, and method set to POST always. It is here for API compatibility reasons alone. * * @param array method value */ public function setMethod($value) { $this->_method = 'POST'; } /* }}} */ /* params Field {{{ */ private $_params; /** * params field getter * * @return array params value */ public function getParams() { return $this->_params; } /** * params field setter * * @param array params value */ public function setParams($value) { $this->_params = $value; } /* }}} */ /* proxy Field {{{ */ private $_proxy = null; /** * proxy field getter * * @return string proxy value */ public function getProxy() { return $this->_proxy; } /** * proxy field setter * * @param string proxy value */ public function setProxy($value) { $this->_proxy = $value; } /* }}} */ /* proxyAuth Field {{{ */ private $_proxyAuth = null; /** * proxyAuth field getter * * @return string proxyAuth value */ public function getProxyAuth() { return $this->_proxyAuth; } /** * proxyAuth field setter * * @param string proxyAuth value */ public function setProxyAuth($value) { $this->_proxyAuth = $value; } /* }}} */ /* uri Field {{{ */ private $_uri; /** * uri field getter * * @return string uri value */ public function getURI() { return $this->_uri; } /** * uri field setter * * @param string uri value */ public function setURI($value) { $this->_uri = $value; } /* }}} */ /* constructor {{{ */ /** * Constructor * * Sets up the object * @param string The uri to fetch/access * @param array Associative array of parameters which can have the following keys: * <ul> * <li>user - Basic Auth username (string)</li> * <li>pass - Basic Auth password (string)</li> * <li>proxy_host - Proxy server host (string)</li> * <li>proxy_port - Proxy server port (integer)</li> * <li>proxy_user - Proxy auth username (string)</li> * <li>proxy_pass - Proxy auth password (string)</li> * </ul> * @access public */ public function __construct($uri = '', $params = array()) { $this->setUri($uri); if (array_key_exists('user', $params) && array_key_exists('pass', $params)) { if (!preg_match('/(https?:\/\/)(.*)/', $uri, $matches)) throw new XML_RPC2_Exception('Unable to parse URI'); $uri = $matches[1] . uriencode($params['user']) . ':' . uriencode($params['pass']) . '@' . $matches[2]; } if (array_key_exists('proxy_host', $params)) { if (!array_key_exists('proxy_port', $params)) { $params['proxy_port'] = 3128; } $this->setProxy("http://{$params['proxy_host']}:{$params['proxy_port']}"); } if (array_key_exists('proxy_user', $params) && array_key_exists('proxy_pass', $params)) { $this->setProxyAuth("{$params['proxy_user']}:{$params['proxy_pass']}"); } } /* }}} */ /* sendRequest {{{ */ /** * Sends the request * * @access public * @return mixed PEAR error on error, true otherwise */ public function sendRequest() { if (!function_exists('curl_init') && !( // TODO Use PEAR::loadExtension once PEAR passes PHP5 unit tests (E_STRICT compliance, namely) @dl('php_curl' . PHP_SHLIB_SUFFIX) || @dl('curl' . PHP_SHLIB_SUFFIX) )) { throw new XML_RPC2_CurlException('cURI extension is not present and load failed'); } if ($ch = curl_init()) { if ( (is_null($this->getProxy()) || curl_setopt($ch, CURLOPT_PROXY, $this->getProxy())) && (is_null($this->getProxyAuth()) || curl_setopt($ch, CURLOPT_PROXYAUTH, $this->getProxyAuth())) && curl_setopt($ch, CURLOPT_URL, $this->getUri()) && curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE) && curl_setopt($ch, CURLOPT_POST, 1) && curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml')) && curl_setopt($ch, CURLOPT_POSTFIELDS, $this->getPostData()) ) { $result = curl_exec($ch); if (($errno = curl_errno($ch)) != 0) { throw new XML_RPC2_CurlException("Curl returned non-null errno $errno:" . curl_error($ch)); } $info = curl_getinfo($ch); if ($info['http_code'] != 200) { throw new XML_RPC2_ReceivedInvalidStatusCodeException('Curl returned non 200 HTTP code: ' . $info['http_code'] . '. Response body:' . $result); } } else { throw new XML_RPC2_CurlException('Unable to setup curl'); } } else { throw new XML_RPC2_CurlException('Unable to init curl'); } $this->setBody($result); return true; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/docs/tutorials/XML_RPC2.lyx?r=1.1&p=1 Index: pear/XML_RPC2/docs/tutorials/XML_RPC2.lyx +++ pear/XML_RPC2/docs/tutorials/XML_RPC2.lyx #LyX 1.3 created this file. For more info see http://www.lyx.org/ \lyxformat 221 \textclass docbook-section \language english \inputencoding auto \fontscheme default \graphics default \paperfontsize default \spacing single \papersize Default \paperpackage a4 \use_geometry 0 \use_amsmath 0 \use_natbib 0 \use_numerical_citations 0 \paperorientation portrait \secnumdepth 3 \tocdepth 3 \paragraph_separation indent \defskip medskip \quotes_language english \quotes_times 2 \papercolumns 1 \papersides 1 \paperpagestyle default \layout Title \added_space_top vfill \added_space_bottom vfill XML_RPC2 Tutorial \layout Abstract This tutorial introduces basic usage of XML_RPC2 as a client/server library in XML_RPC operations. XML_RPC2 is a pear package providing XML_RPC client and server services. XML-RPC is a simple remote procedure call protocol built using HTTP as transport and XML as encoding. \layout Abstract As a client library, XML_RPC2 is capable of creating a proxy class which exposes the methods exported by the server. As a server library, XML_RPC2 is capable of exposing methods from a class or object instance, seamlessly exporting local methods as remotely callable procedures. \layout Subsection Client usage \layout Subsubsection Basic Usage \layout Standard The most simple way to use the XML_RPC client is by letting XML_RPC2 select the backend for you, and just give the client factory method the data referring to the server: \layout Itemize The server URI. \layout Itemize The HTTP proxy URI (null if no proxy). \layout Itemize The method prefix \layout Code require_once('XML/RPC2/Client.php'); \layout Code $client = XML_RPC2_Client::create('http://rpc.example.com:80/', null, ''); \layout Standard The factory will produce a client proxy. This class exports whichever methods the server exports. These methods are called just like regular local methods: \layout Code print($client->hello('World')); \layout Standard for a server that exports the method hello. If the server has methods prefixed by a classname (example.hello), there are two solutions. Either call the method using brackets enclosing the otherwise php-invalid method name: \layout Code print($client->{example.hello}('World')); \layout Standard Or specify a method prefix when creating the client instance: \layout Code $client = XML_RPC2_Client::create('http://rpc.example.com:80/', null, 'example.'); \layout Code print($client->hello('World')); \layout Subsubsection Error handling \layout Standard XML_RPC2 uses exceptions to signal errors. The phpdoc reference contains a class hierarchy useful to get a grasp of possible errors. The most important characteristics of the XML_RPC2 exception tree are: \layout Itemize All XML_RPC2 exceptions are children of XML_RPC2_Exception. If you want to filter out exceptions from this package, catch XML_RPC2_Exceptio n \layout Itemize Network failure is signaled by an XML_RPC2_TransportException \layout Itemize Regular XML-RPC fault responses are signaled by an XML_RPC2_FaultException \layout Itemize All other types of XML_RPC2_Exception signal package misuse or bug-induced misbehaviour \layout Standard Standard usage: \layout Code require_once('XMLrequire_once('XML/RPC2/Client.php'); \layout Code try { \layout Code $client = XML_RPC2_Client::create('http://rpc.example.com:80/', null, ''); \layout Code print($client->hello('World')); \layout Code } catch (XML_RPC2_TransportException transportException) { \layout Code // Handle network-induced exception \layout Code } catch (XML_RPC2_FaultException fault) { \layout Code // Handle fault returned by remote server \layout Code } catch (XML_RPC2_Exception xmlRpcException) { \layout Code // Handle abnormal XML_RPC2 package exception \layout Code } catch (Exception e) { \layout Code // Handle someone else's fault exception \layout Code } \layout Standard It is good practice to at least expect XML_RPC2_TransportException as network failure can't ever be ruled out. \layout Subsection Server usage \layout Subsubsection Basic Usage \layout Standard To export an XML-RPC server using XML_RPC2, the first step is writing the methods to export. XML_RPC2 can export class methods (static methods) for a class, or all methods for an object instance. For this example, we'll export a class' static methods: \layout Code class EchoServer { \layout Code /** \layout Code * echoecho echoes the message received \layout Code * \layout Code * @param string Message \layout Code * @return string The echo \layout Code */ \layout Code \layout Code public static function echoecho($string) \layout Code { \layout Code return $string; \layout Code } \layout Code \layout Code /** \layout Code * Dummy method which won't be exported \layout Code * \layout Code * @xmlrpc.hidden \layout Code */ \layout Code public static function dummy() \layout Code { \layout Code return false; \layout Code } \layout Code \layout Code /** \layout Code * hello says hello \layout Code * \layout Code * @param string Name \layout Code * @return string Hello 'name' \layout Code */ \layout Code public function hello($name) \layout Code { \layout Code return "Hello $name"; \layout Code } \layout Code \layout Code } \layout Standard Note that the method is documented using phpDoc docblocks. The docblock is used to deduce the signature and method documentation, required by the XML-RPC spec. Non-documented methods are not exported. Methods tagged with the tag @xmlrpc.hidden are not exported either (the dummy method above won't be exported). \layout Standard After creating the class, we need to get an XML_RPC2 server to export its methods remotely: \layout Code require_once 'XML/RPC2/Server.php'; \layout Code $server = XML_RPC2_Server::create('EchoServer'); \layout Code $server->handleCall(); \layout Standard The XML_RPC2_Server automatically exports all of the EchoServer class public static methods (echoecho in this case). You may also export all of an instance's public methods (static or otherwise): \layout Code require_once 'XML/RPC2/Server.php'; \layout Code $server = XML_RPC2_Server::create(new EchoServer()); \layout Code $server->handleCall(); \the_end http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/client/faultFromPython.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/client/faultFromPython.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/client/faultFromPython.phpt --TEST-- PHP Backend XML-RPC client against python server returning fault response --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Client.php'; require_once 'XML/RPC2/Backend.php'; XML_RPC2_Backend::setBackend('php'); $client = XML_RPC2_Client::create('http://python.xmlrpc2test.sergiocarvalho.com:8765', '', null); try { $client->invalidMethod('World'); } catch (XML_RPC2_FaultException $e) { var_dump($e->getMessage()); } ?> --EXPECT-- string(60) "exceptions.Exception:method "invalidMethod" is not supported" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/client/okFromPython.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/client/okFromPython.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/client/okFromPython.phpt --TEST-- PHP Backend XML-RPC client against python server returning normal response --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Client.php'; require_once 'XML/RPC2/Backend.php'; XML_RPC2_Backend::setBackend('php'); $client = XML_RPC2_Client::create('http://python.xmlrpc2test.sergiocarvalho.com:8765', '', null); var_dump($client->echo('World')); ?> --EXPECT-- string(5) "World" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/client/protocolError.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/client/protocolError.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/client/protocolError.phpt --TEST-- PHP Backend XML-RPC client with transport error --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Client.php'; require_once 'XML/RPC2/Backend.php'; XML_RPC2_Backend::setBackend('php'); $client = XML_RPC2_Client::create('http://rpc.example.com:1000/', '', null); try { $client->invalidMethod('World'); } catch (XML_RPC2_CurlException $e) { var_dump($e->getMessage()); } ?> --EXPECTREGEX-- string\(.*\) \"Curl returned non-null errno.* http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/array.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/array.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/array.phpt --TEST-- Array XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Value.php'); var_dump(XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<?xml version="1.0"?><value><array><data><value><int>1</int></value><value><boolean>1</boolean></value><value><string>a</string></value></data></array></value>'))->getNativeValue()); ?> --EXPECT-- array(3) { [0]=> int(1) [1]=> bool(true) [2]=> string(1) "a" } http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/base64.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/base64.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/base64.phpt --TEST-- Base64 XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Value.php'); printf("Native value: %s\n", XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<?xml version="1.0"?><value><base64>VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2c=</base64></value>'))->getNativeValue()); ?> --EXPECT-- Native value: The quick brown fox jumped over the lazy dog http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/boolean.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/boolean.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/boolean.phpt --TEST-- Boolean XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Value.php'); printf("Native value: %s\n", XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<?xml version="1.0"?><value><boolean>0</boolean></value>'))->getNativeValue() ? 'true' : 'false'); printf("Native value: %s\n", XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<?xml version="1.0"?><value><boolean>1</boolean></value>'))->getNativeValue() ? 'true' : 'false'); ?> --EXPECT-- Native value: false Native value: true http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/datetime.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/datetime.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/datetime.phpt --TEST-- Datetime XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Value.php'); printf("Native value: %s\n", XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<?xml version="1.0"?><value><dateTime.iso8601>2005</dateTime.iso8601></value>'))->getNativeValue()); ?> --EXPECT-- Native value: 1104537600 http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/double.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/double.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/double.phpt --TEST-- Double XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Value.php'); printf("Native value: %s\n", XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<?xml version="1.0"?><value><double>1.25</double></value>'))->getNativeValue()); ?> --EXPECT-- Native value: 1.25 http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/faultResponse.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/faultResponse.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/faultResponse.phpt --TEST-- Response XML-RPC decoding (Php Backend) --FILE-- <?php try { set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Response.php'); var_dump(XML_RPC2_Backend_Php_Response::decode(simplexml_load_string(<<<XMLMARKER <?xml version="1.0"?> <methodResponse> <fault> <value><struct> <member><name>faultString</name><value><string>Failed to create homedir with: 0</string></value></member> <member><name>faultCode</name><value><i4>200</i4></value></member> </struct></value> </fault> </methodResponse> XMLMARKER ))); } catch (Exception $e) { var_dump($e->getMessage()); } ?> --EXPECT-- string(32) "Failed to create homedir with: 0" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/integer.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/integer.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/integer.phpt --TEST-- Integer XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Value.php'); printf("Native value: %s\n", XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<?xml version="1.0"?><value><int>13</int></value>'))->getNativeValue()); ?> --EXPECT-- Native value: 13 http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/integer2.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/integer2.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/integer2.phpt --TEST-- Integer XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Value.php'); printf("Native value: %s\n", XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<?xml version="1.0"?><value><i4>7</i4></value>'))->getNativeValue()); ?> --EXPECT-- Native value: 7 http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/request.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/request.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/request.phpt --TEST-- Request XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Request.php'); $request = XML_RPC2_Backend_Php_Request::createFromDecode(simplexml_load_string('<?xml version="1.0"?><methodCall><methodName>foo.bar</methodName><params><param><value><string>a string</string></value></param><param><value><int>125</int></value></param><param><value><double>125.2</double></value></param><param><value><dateTime.iso8601>19970716192030</dateTime.iso8601></value></param><param><value><boolean>1</boolean></value></param><param><value><boolean>0</boolean></value></param></params></methodCall>')); var_dump($request->getMethodName()); var_dump($request->getParameters()); ?> --EXPECT-- string(7) "foo.bar" array(6) { [0]=> string(8) "a string" [1]=> int(125) [2]=> float(125.2) [3]=> float(869011200) [4]=> bool(true) [5]=> bool(false) } http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/response.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/response.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/response.phpt --TEST-- Response XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Response.php'); var_dump(XML_RPC2_Backend_Php_Response::decode(simplexml_load_string('<?xml version="1.0"?><methodResponse><params><param><value><string>South Dakota</string></value></param></params></methodResponse>'))); ?> --EXPECT-- string(12) "South Dakota" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/string.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/string.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/string.phpt --TEST-- String XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Value.php'); printf("Native value: %s\n", XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<?xml version="1.0"?><value><string>The quick brown fox jumped over the lazy dog</string></value>'))->getNativeValue()); ?> --EXPECT-- Native value: The quick brown fox jumped over the lazy dog http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/struct.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/struct.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/struct.phpt --TEST-- Struct XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Value.php'); var_dump(XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<value><struct><member><name>a</name><value><int>1</int></value></member><member><name>b</name><value><boolean>1</boolean></value></member><member><name>c</name><value><string>a string</string></value></member></struct></value>'))->getNativeValue()); ?> --EXPECT-- array(3) { ["a"]=> int(1) ["b"]=> bool(true) ["c"]=> string(8) "a string" } http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/array.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/array.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/array.phpt --TEST-- Array XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Array.php'; $array = new XML_RPC2_Backend_Php_Value_Array(array(1, true, 'a string')); var_dump($array->encode()); ?> --EXPECT-- string(130) "<array><data><value><int>1</int></value><value><boolean>1</boolean></value><value><string>a string</string></value></data></array>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/base64.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/base64.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/base64.phpt --TEST-- Base64 XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Base64.php'; $string = new XML_RPC2_Backend_Php_Value_Base64('The quick brown fox jumped over the lazy dog'); var_dump($string->encode()); $string = new XML_RPC2_Backend_Php_Value_Base64('The <quick> brown fox jumped over the lazy dog'); var_dump($string->encode()); ?> --EXPECT-- string(77) "<base64>VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2c=</base64>" string(81) "<base64>VGhlIDxxdWljaz4gYnJvd24gZm94IGp1bXBlZCBvdmVyIHRoZSBsYXp5IGRvZw==</base64>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/boolean.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/boolean.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/boolean.phpt --TEST-- Boolean XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Boolean.php'; $bool = new XML_RPC2_Backend_Php_Value_Boolean(true); var_dump($bool->encode()); $bool = new XML_RPC2_Backend_Php_Value_Boolean(false); var_dump($bool->encode()); ?> --EXPECT-- string(20) "<boolean>1</boolean>" string(20) "<boolean>0</boolean>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime.phpt --TEST-- Datetime XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Datetime.php'; $time = new XML_RPC2_Backend_Php_Value_Datetime(853438830.45); var_dump($time->encode()); ?> --EXPECT-- string(49) "<dateTime.iso8601>853438830.45</dateTime.iso8601>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime1.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime1.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime1.phpt --TEST-- Datetime XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Datetime.php'; $time = new XML_RPC2_Backend_Php_Value_Datetime('1997-01-16T19:20:30.45+01:00'); var_dump($time->encode()); ?> --EXPECT-- string(49) "<dateTime.iso8601>853438830.45</dateTime.iso8601>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime2.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime2.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime2.phpt --TEST-- Datetime XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Datetime.php'; $time = new XML_RPC2_Backend_Php_Value_Datetime('1997-01-16T19:20:30.45Z'); var_dump($time->encode()); ?> --EXPECT-- string(49) "<dateTime.iso8601>853442430.45</dateTime.iso8601>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime3.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime3.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime3.phpt --TEST-- Datetime XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Datetime.php'; $time = new XML_RPC2_Backend_Php_Value_Datetime('2001'); var_dump($time->encode()); ?> --EXPECT-- string(46) "<dateTime.iso8601>978307200</dateTime.iso8601>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime4.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime4.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime4.phpt --TEST-- Datetime XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Datetime.php'; $time = new XML_RPC2_Backend_Php_Value_Datetime('1997-01-16'); var_dump($time->encode()); ?> --EXPECT-- string(46) "<dateTime.iso8601>853372800</dateTime.iso8601>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/double.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/double.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/double.phpt --TEST-- Double XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Double.php'; $double = new XML_RPC2_Backend_Php_Value_Double(0); var_dump($double->encode()); $double = new XML_RPC2_Backend_Php_Value_Double(123.79); var_dump($double->encode()); ?> --EXPECT-- string(18) "<double>0</double>" string(23) "<double>123.79</double>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/integer.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/integer.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/integer.phpt --TEST-- Integer XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Integer.php'; $integer = new XML_RPC2_Backend_Php_Value_Integer(53); var_dump($integer->encode()); ?> --EXPECT-- string(13) "<int>53</int>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/request.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/request.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/request.phpt --TEST-- Request XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Request.php'; require_once 'XML/RPC2/Backend/Php/Value/Datetime.php'; $request = new XML_RPC2_Backend_Php_Request('foo.bar'); $request->addParameter('a string'); $request->addParameter(125); $request->addParameter(125.2); $request->addParameter(new XML_RPC2_Backend_Php_Value_Datetime('2005-01-03')); $request->addParameter(true); $request->addParameter(false); var_dump($request->encode()); ?> --EXPECT-- string(423) "<?xml version="1.0"?><methodCall><methodName>foo.bar</methodName><params><param><value><string>a string</string></value></param><param><value><int>125</int></value></param><param><value><double>125.2</double></value></param><param><value><dateTime.iso8601>1104710400</dateTime.iso8601></value></param><param><value><boolean>1</boolean></value></param><param><value><boolean>0</boolean></value></param></params></methodCall>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/response.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/response.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/response.phpt --TEST-- Request XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Response.php'; var_dump(XML_RPC2_Backend_Php_Response::encode(array(1, true, 'a string'))); ?> --EXPECT-- string(231) "<?xml version="1.0"?><methodResponse><params><param><value><array><data><value><int>1</int></value><value><boolean>1</boolean></value><value><string>a string</string></value></data></array></value></param></params></methodResponse>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/response2.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/response2.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/response2.phpt --TEST-- Request XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Response.php'; var_dump(XML_RPC2_Backend_Php_Response::encodeFault(2,'A fault string')); ?> --EXPECT-- string(254) "<?xml version="1.0"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>2</int></value></member><member><name>faultString</name><value><string>A fault string</string></value></member></struct></value></fault></methodResponse>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/string.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/string.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/string.phpt --TEST-- String XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/String.php'; $string = new XML_RPC2_Backend_Php_Value_String('The quick brown fox jumped over the lazy dog'); var_dump($string->encode()); $string = new XML_RPC2_Backend_Php_Value_String('The <quick> brown fox jumped over the lazy dog'); var_dump($string->encode()); ?> --EXPECT-- string(61) "<string>The quick brown fox jumped over the lazy dog</string>" string(69) "<string>The <quick> brown fox jumped over the lazy dog</string>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/struct.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/struct.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/struct.phpt --TEST-- Struct XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Struct.php'; $struct = new XML_RPC2_Backend_Php_Value_Struct(array('a' => 1, 'b' => true, 'c' => 'a string')); var_dump($struct->encode()); ?> --EXPECT-- string(212) "<struct><member><name>a</name><value><int>1</int></value></member><member><name>b</name><value><boolean>1</boolean></value></member><member><name>c</name><value><string>a string</string></value></member></struct>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/server/invalidXMLRequest.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/server/invalidXMLRequest.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/server/invalidXMLRequest.phpt --TEST-- PHP Backend XML-RPC server with non-existant method response --FILE-- <?php class EchoServer { /** * echoecho echoes the message received * * @param string Message * @return string The echo */ public static function echoecho($string) { return $string; } } set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend.php'; require_once 'XML/RPC2/Server.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; XML_RPC2_Backend::setBackend('php'); $server = XML_RPC2_Server::create('EchoServer'); $GLOBALS['HTTP_RAW_POST_DATA'] = <<<EOS <?xml version="1.0"?> <methodCall> <methodName>echoecho</methodName> <params><param><value><string>World</string></value></param></prams> </methodCall> EOS ; ob_start(); $server->handleCall(); $response = ob_get_contents(); ob_end_clean(); try { XML_RPC2_Backend_Php_Response::decode(simplexml_load_string($response)); } catch (XML_RPC2_FaultException $e) { var_dump($e->getMessage()); } ?> --EXPECT-- string(27) "Unable to parse request XML" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/server/nonexistantMethod.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/server/nonexistantMethod.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/server/nonexistantMethod.phpt --TEST-- PHP Backend XML-RPC server with non-existant method response --FILE-- <?php class EchoServer { /** * echoecho echoes the message received * * @param string Message * @return string The echo */ public static function echoecho($string) { return $string; } } set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend.php'; require_once 'XML/RPC2/Server.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; XML_RPC2_Backend::setBackend('php'); $server = XML_RPC2_Server::create('EchoServer'); $GLOBALS['HTTP_RAW_POST_DATA'] = <<<EOS <?xml version="1.0"?> <methodCall> <methodName>example</methodName> <params><param><value><string>World</string></value></param></params> </methodCall> EOS ; ob_start(); $server->handleCall(); $response = ob_get_contents(); ob_end_clean(); try { XML_RPC2_Backend_Php_Response::decode(simplexml_load_string($response)); } catch (XML_RPC2_FaultException $e) { var_dump($e->getMessage()); } ?> --EXPECT-- string(97) "Unhandled XML_RPC2_UnknownMethodException exception:Method example is not exported by this server" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/server/normalRequest.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/server/normalRequest.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/server/normalRequest.phpt --TEST-- PHP Backend XML-RPC server with normal response --FILE-- <?php class EchoServer { /** * echoecho echoes the message received * * @param string Message * @return string The echo */ public static function echoecho($string) { return $string; } } set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend.php'; require_once 'XML/RPC2/Server.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; XML_RPC2_Backend::setBackend('php'); $server = XML_RPC2_Server::create('EchoServer'); $GLOBALS['HTTP_RAW_POST_DATA'] = <<<EOS <?xml version="1.0"?> <methodCall> <methodName>echoecho</methodName> <params><param><value><string>World</string></value></param></params> </methodCall> EOS ; ob_start(); $server->handleCall(); $response = ob_get_contents(); ob_end_clean(); var_dump(XML_RPC2_Backend_Php_Response::decode(simplexml_load_string($response))); ?> --EXPECT-- string(5) "World" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/faultFromPython.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/faultFromPython.phpt +++ pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/faultFromPython.phpt --TEST-- XMLRPCext Backend XML-RPC client against python server returning fault response --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Client.php'; require_once 'XML/RPC2/Backend.php'; XML_RPC2_Backend::setBackend('xmlrpcext'); $client = XML_RPC2_Client::create('http://python.xmlrpc2test.sergiocarvalho.com:8765', '', null); try { $client->invalidMethod('World'); } catch (XML_RPC2_FaultException $e) { var_dump($e->getMessage()); } ?> --EXPECT-- string(60) "exceptions.Exception:method "invalidMethod" is not supported" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/okFromPython.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/okFromPython.phpt +++ pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/okFromPython.phpt --TEST-- XMLRPCext Backend XML-RPC client against python server returning normal response --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Client.php'; require_once 'XML/RPC2/Backend.php'; XML_RPC2_Backend::setBackend('xmlrpcext'); $client = XML_RPC2_Client::create('http://python.xmlrpc2test.sergiocarvalho.com:8765', '', null); var_dump($client->echo('World')); ?> --EXPECT-- string(5) "World" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/protocolError.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/protocolError.phpt +++ pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/protocolError.phpt --TEST-- XMLRPCext Backend XML-RPC client with transport error --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Client.php'; require_once 'XML/RPC2/Backend.php'; XML_RPC2_Backend::setBackend('xmlrpcext'); $client = XML_RPC2_Client::create('http://rpc.example.com:1000/', '', null); try { $client->invalidMethod('World'); } catch (XML_RPC2_CurlException $e) { var_dump($e->getMessage()); } ?> --EXPECT-- string(70) "Curl returned non-null errno 6:Couldn't resolve host 'rpc.example.com'" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/valueCreateFromNative.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/valueCreateFromNative.phpt +++ pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/valueCreateFromNative.phpt --TEST-- XMLRPCext backend test setting explicit type for value --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Value.php'; require_once 'XML/RPC2/Backend.php'; XML_RPC2_Backend::setBackend('xmlrpcext'); var_dump(XML_RPC2_Value::createFromNative('Hello World', 'base64')); ?> --EXPECT-- object(stdClass)#1 (2) { ["scalar"]=> string(11) "Hello World" ["xmlrpc_type"]=> string(6) "base64" } http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server/invalidXMLRequest.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server/invalidXMLRequest.phpt +++ pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server/invalidXMLRequest.phpt --TEST-- XMLRPCext Backend XML-RPC server with normal response --SKIPIF-- <?php // I can't silence expat errors anyhow. We're skipping this test // for xmlrpci print "skip"; --FILE-- <?php class EchoServer { /** * echoecho echoes the message received * * @param string Message * @return string The echo */ public static function echoecho($string) { return $string; } } set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend.php'; require_once 'XML/RPC2/Server.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; XML_RPC2_Backend::setBackend('XMLRPCext'); $server = XML_RPC2_Server::create('EchoServer'); $GLOBALS['HTTP_RAW_POST_DATA'] = <<<EOS <?xml version="1.0"?> <methodCall> <methodName>moo</methodName> <params><param><value><string>World</string></value></param></prams> </methodCall> EOS ; try { ob_start(); $server->handleCall(); $response = ob_get_contents(); ob_end_clean(); //print($response); //XML_RPC2_Backend_Php_Response::decode(simplexml_load_string($response)); } catch (XML_RPC2_FaultException $e) { var_dump($e->getMessage()); } ?> --EXPECT-- string(36) "server error. method not found. moo" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server/nonexistantMethod.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server/nonexistantMethod.phpt +++ pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server/nonexistantMethod.phpt --TEST-- XMLRPCext Backend XML-RPC server with normal response --FILE-- <?php class EchoServer { /** * echoecho echoes the message received * * @param string Message * @return string The echo */ public static function echoecho($string) { return $string; } } set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend.php'; require_once 'XML/RPC2/Server.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; XML_RPC2_Backend::setBackend('XMLRPCext'); $server = XML_RPC2_Server::create('EchoServer'); $GLOBALS['HTTP_RAW_POST_DATA'] = <<<EOS <?xml version="1.0"?> <methodCall> <methodName>moo</methodName> <params><param><value><string>World</string></value></param></params> </methodCall> EOS ; ob_start(); $server->handleCall(); $response = ob_get_contents(); ob_end_clean(); try { XML_RPC2_Backend_Php_Response::decode(simplexml_load_string($response)); } catch (XML_RPC2_FaultException $e) { var_dump($e->getMessage()); } ?> --EXPECT-- string(36) "server error. method not found. moo" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server/normalRequest.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server/normalRequest.phpt +++ pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server/normalRequest.phpt --TEST-- XMLRPCext Backend XML-RPC server with normal response --FILE-- <?php class EchoServer { /** * echoecho echoes the message received * * @param string Message * @return string The echo */ public static function echoecho($string) { return $string; } } set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend.php'; require_once 'XML/RPC2/Server.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; XML_RPC2_Backend::setBackend('XMLRPCext'); $server = XML_RPC2_Server::create('EchoServer'); $GLOBALS['HTTP_RAW_POST_DATA'] = <<<EOS <?xml version="1.0"?> <methodCall> <methodName>echoecho</methodName> <params><param><value><string>World</string></value></param></params> </methodCall> EOS ; ob_start(); $server->handleCall(); $response = ob_get_contents(); ob_end_clean(); var_dump(XML_RPC2_Backend_Php_Response::decode(simplexml_load_string($response))); ?> --EXPECT-- string(5) "World" http://cvs.php.net/co.php/pear/XML_RPC2/util/filelist.sh?r=1.1&p=1 Index: pear/XML_RPC2/util/filelist.sh +++ pear/XML_RPC2/util/filelist.sh #!/bin/bash listdir () { if [ "$i" = '.' ]; then return; fi if [ "$i" = '..' ]; then return; fi if [ -d $1 ] then echo "<dir name=\"$(basename $1)\" role=\"$2\">" cd $1 for i in `ls -1` do listdir $i $2 done cd .. echo "</dir>" else echo "<file name=\"$(basename $1)\" />" fi } listdir XML php listdir tests/XML_RPC2 test http://cvs.php.net/co.php/pear/XML_RPC2/util/indent.xsl?r=1.1&p=1 Index: pear/XML_RPC2/util/indent.xsl +++ pear/XML_RPC2/util/indent.xsl <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="/"> <xsl:copy-of select="."/> </xsl:template> </xsl:stylesheet>
http://cvs.php.net/co.php/pear/XML_RPC2/package.xml?r=1.1&p=1 Index: pear/XML_RPC2/package.xml +++ pear/XML_RPC2/package.xml <?xml version="1.0"?> <package version="1.0"> <!-- $Id: package.xml,v 1.1 2005/11/29 21:41:26 sergiosgc Exp $ --> <name>XML_RPC2</name> <summary>XML-RPC client/server library</summary> <description> XML_RPC2 is a pear package providing XML_RPC client and server services. XML-RPC is a simple remote procedure call protocol built using HTTP as transport and XML as encoding. As a client library, XML_RPC2 is capable of creating a proxy class which exposes the methods exported by the server. As a server library, XML_RPC2 is capable of exposing methods from a class or object instance, seamlessly exporting local methods as remotely callable procedures. </description> <license>LGPL</license> <maintainers> <maintainer> <user>sergiosgc</user> <role>lead</role> <name>Sérgio Carvalho</name> <email>sergio.carvalho@portugalmail.com</email> </maintainer> </maintainers> <release> <version>0.0.5</version> <state>alpha</state> <date>2005-09-07</date> <notes> Implemented changes requested during package voting </notes> <filelist> <dir name="XML" role="php"> <dir name="RPC2" role="php"> <dir name="Backend" role="php"> <dir name="Php" role="php"> <file name="Client.php"/> <file name="Request.php"/> <file name="Response.php"/> <file name="Server.php"/> <dir name="Value" role="php"> <file name="Array.php"/> <file name="Base64.php"/> <file name="Boolean.php"/> <file name="Datetime.php"/> <file name="Double.php"/> <file name="Integer.php"/> <file name="Scalar.php"/> <file name="String.php"/> <file name="Struct.php"/> </dir> <file name="Value.php"/> </dir> <dir name="Xmlrpcext" role="php"> <file name="Client.php"/> <file name="Server.php"/> <file name="Value.php"/> </dir> </dir> <file name="Backend.php"/> <file name="Client.php"/> <file name="Exception.php"/> <dir name="Server" role="php"> <dir name="CallHandler" role="php"> <file name="Class.php"/> <file name="Instance.php"/> </dir> <file name="CallHandler.php"/> <file name="Method.php"/> </dir> <file name="Server.php"/> <dir name="Util" role="php"> <file name="HTTPRequest.php"/> </dir> <file name="Value.php"/> </dir> </dir> <dir name="XML_RPC2" role="test"> <dir name="phpBackend" role="test"> <dir name="client" role="test"> <file name="faultFromPython.phpt"/> <file name="okFromPython.phpt"/> <file name="protocolError.phpt"/> </dir> <dir name="decoding" role="test"> <file name="array.phpt"/> <file name="base64.phpt"/> <file name="boolean.phpt"/> <file name="datetime.phpt"/> <file name="double.phpt"/> <file name="faultResponse.phpt"/> <file name="integer2.phpt"/> <file name="integer.phpt"/> <file name="request.phpt"/> <file name="response.phpt"/> <file name="string.phpt"/> <file name="struct.phpt"/> </dir> <dir name="encoding" role="test"> <file name="array.phpt"/> <file name="base64.phpt"/> <file name="boolean.phpt"/> <file name="datetime1.phpt"/> <file name="datetime2.phpt"/> <file name="datetime3.phpt"/> <file name="datetime4.phpt"/> <file name="datetime.phpt"/> <file name="double.phpt"/> <file name="integer.phpt"/> <file name="request.phpt"/> <file name="response2.phpt"/> <file name="response.phpt"/> <file name="string.phpt"/> <file name="struct.phpt"/> </dir> <dir name="server" role="test"> <file name="invalidXMLRequest.phpt"/> <file name="nonexistantMethod.phpt"/> <file name="normalRequest.phpt"/> </dir> </dir> <dir name="xmlrpcextBackend" role="test"> <dir name="client" role="test"> <file name="faultFromPython.phpt"/> <file name="okFromPython.phpt"/> <file name="protocolError.phpt"/> <file name="valueCreateFromNative.phpt"/> </dir> <dir name="server" role="test"> <file name="invalidXMLRequest.phpt"/> <file name="nonexistantMethod.phpt"/> <file name="normalRequest.phpt"/> </dir> </dir> </dir> </filelist> <deps> <dep type="php" rel="ge" version="5.0.0"/> <dep type="pkg" rel="ge" version="1.0b1">PEAR</dep> </deps> </release> </package> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend.php +++ pear/XML_RPC2/XML/RPC2/Backend.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; /* }}} */ /** * XML_RPC Backend class. The backend is responsible for the actual execution of * a request, as well as payload encoding and decoding. * * The only external usage of this class is when explicitely setting the backend, as in * <code> * XML_RPC2_Backend::setBackend('php'); * // or * XML_RPC2_Backend::setBackend('xmlrpcext'); * </code> * Note that if you do not explicitely set the backend, it will be selected automatically. * * Internally, this class provides methods to obtain the relevant backend classes: * - The server class * - The client class * - The value class * * @author Sérgio Carvalho * @package XML_RPC2 */ abstract class XML_RPC2_Backend { protected static $currentBackend; /* setBackend {{{ */ /** * Backend setter. * * Currently, two backends exist: 'php' and 'XMLRPCext'. * The PHP backend has no external dependencies, while the xmlrpcext * requires the xmlrpc extension. * * The XMLRPCext backend is quite faster, and will be automatically * selected when no explicit backend has been set and the extension * is available. * * @param string The backend to select. Either 'php' or 'XMLRPCext'. */ public static function setBackend($backend) { $backend = ucfirst(strtolower($backend)); if ( $backend != 'Php' && $backend != 'Xmlrpcext' ) { throw new XML_RPC2_Exception(sprintf('Backend %s does not exist', $backend)); } if ( $backend == 'Xmlrpcext' && !function_exists('xmlrpc_server_create') && !( // TODO Use PEAR::loadExtension once PEAR passes PHP5 unit tests (E_STRICT compliance, namely) @dl('php_xmlrpc' . PHP_SHLIB_SUFFIX) || @dl('xmlrpc' . PHP_SHLIB_SUFFIX) ) ) { throw new XML_RPC2_Exception('Unable to load xmlrpc extension.'); } self::$currentBackend = $backend; } /* }}} */ /* getBackend {{{ */ /** * Backend getter. * * Return the current backend name. If no backend was previously selected * elect one and set it. * * The xmlrpcext backend is preferred, and will be automatically * selected when no explicit backend has been set and the xmlrpc * extension exists. If it does not exist, then the php backend is * selected. * * @return string The current backend */ protected static function getBackend() { if (!isset(self::$currentBackend)) { try { self::setBackend('XMLRPCext'); // We prefer this one } catch (XML_RPC2_Exception $e) { // TODO According to PEAR CG logging should occur here self::setBackend('php'); // But will settle with this one in case of error } } return self::$currentBackend; } /* }}} */ /* getServerClassname {{{ */ /** * Include the relevant php files for the server class, and return the backend server * class name. * * @return string The Server class name */ public static function getServerClassname() { require_once(sprintf('XML/RPC2/Backend/%s/Server.php', self::getBackend())); return sprintf('XML_RPC2_Backend_%s_Server', self::getBackend()); } /* }}} */ /* getClientClassname {{{ */ /** * Include the relevant php files for the client class, and return the backend client * class name. * * @return string The Client class name */ public static function getClientClassname() { require_once(sprintf('XML/RPC2/Backend/%s/Client.php', self::getBackend())); return sprintf('XML_RPC2_Backend_%s_Client', self::getBackend()); } /* }}} */ /* getValueClassname {{{ */ /** * Include the relevant php files for the value class, and return the backend value * class name. * * @return string The Value class name */ public static function getValueClassname() { require_once(sprintf('XML/RPC2/Backend/%s/Value.php', self::getBackend())); return sprintf('XML_RPC2_Backend_%s_Value', self::getBackend()); } /* }}} */ } http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Client.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Client.php +++ pear/XML_RPC2/XML/RPC2/Client.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend.php'; /* }}} /* /** * XML_RPC client class. Use this class to access remote methods. * * To use this class, construct it providing the server URL and method prefix. * Then, call remote methods on the new instance as if they were local. * * Example: * <code> * require_once 'XML_RPC2/Client.php'; * * $client = XML_RPC2_Client('http://xmlrpc.example.com/1.0/', 'example.'); * $result = $client->hello('Sérgio'); * print($result); * </code> * * The above example will call the example.hello method on the xmlrpc.example.com * server, under the /1.0/ URI. * * @package XML_RPC2 * @author Sérgio Carvalho */ abstract class XML_RPC2_Client { /* uri Field {{{ */ /** Holds the uri for the XML_RPC server */ protected $_uri = null; /** uri setter */ protected function setUri($uri) { if (!$uriParse = parse_url($uri)) { throw new XML_RPC2_InvalidUriException(sprintf('Client URI \'%s\' is not valid', $uri)); } $this->_uri = $uriParse; foreach (array_keys($this->_uri) as $key) { $this->_uri[$key] = urldecode($this->_uri[$key]); } $this->_uri['uri'] = $uri; } /** uri getter */ protected function getUri() { return $this->_uri['uri']; } /* }}} */ /* proxy Field {{{ */ /** Holds the proxy server data */ protected $_proxy = null; /** proxy setter */ protected function setProxy($proxy) { if (is_null($proxy)) { $this->_proxy = null; return; } if (!$proxyParse = parse_url($proxy)) throw new XML_RPC2_InvalidProxyException(sprintf('Proxy URI \'%s\' is not valid', $proxy)); $this->_proxy = $proxyParse; foreach (array_keys($this->_proxy) as $key) { $this->_proxy[$key] = urldecode($this->_proxy[$key]); } $this->_proxy['uri'] = $proxy; } /** proxy getter */ protected function getProxy() { return $this->_proxy['uri']; } /* }}} */ /* prefix Field {{{ */ /** Holds the prefix to prepend to method names */ protected $_prefix = null; /** prefix setter */ protected function setPrefix($prefix) { $this->_prefix = $prefix; } /** prefix getter */ protected function getPrefix() { return $this->_prefix; } /* }}} */ /* debug Field {{{ */ /** Holds the debug flag */ protected $_debug = false; /** debug setter */ public function setDebug($debug) { $this->_debug = $debug; } /** debug getter */ public function getDebug() { return $this->_debug; } /* }}} */ /* remoteCall(abstract) {{{ */ /** * remoteCall executes the XML-RPC call, and returns the result * * @param string Method name * @param array Parameters */ public abstract function remoteCall($methodName, $parameters); /* }}} */ /* constructor {{{ */ /** * Construct a new XML_RPC2_Client. * * To create a new XML_RPC2_Client, a URI must be provided (e.g. http://xmlrpc.example.com/1.0/). * Optionally, a prefix may be set, wich will be prepended to method names, before calling. * Prefixes are extremely useful namely when method names contain a period '.' turning them invalid * under PHP syntax. * Optionally, an encoding may be set. If set, it will be indicated in the request XML document, and * the response will be converted from its encoding to the designated encoding. * The fifth parameter, optional, allows for debugging to be turned on, by passing a boolean true value. * * @param string URI for the XML-RPC server * @param string (optional) Prefix to prepend on all called functions (defaults to '') * @param string (optional) Proxy server URI (defaults to no proxy) * */ protected function __construct($uri, $prefix = '', $proxy = null) { $this->setUri($uri); $this->setProxy($proxy); $this->setPrefix($prefix); } /* }}} */ /* create {{{ */ /** * Factory method to select, create and return a XML_RPC2_Client backend * * To create a new XML_RPC2_Client, a URI must be provided (e.g. http://xmlrpc.example.com/1.0/). * * Optionally, a prefix may be set, wich will be prepended to method names, before calling. * Prefixes are extremely useful namely when method names contain a period '.' turning them invalid * under PHP syntax. * * You may also set a proxy server, through where the requests will be sent. * * @param string URI for the XML-RPC server * @param string (optional) Prefix to prepend on all called functions (defaults to '') * @param string (optional) Proxy server URI (defaults to no proxy) * */ public static function create($uri, $prefix = '', $proxy = null) { $backend = XML_RPC2_Backend::getClientClassname(); return new $backend($uri, $prefix, $proxy); } /* }}} */ /* __call {{{ */ /** * __call Catchall. This method catches remote method calls and provides for remote forwarding. * * If the parameters are native types, this method will use XML_RPC_Value::createFromNative to * convert it into an XML-RPC type. Whenever a parameter is already an instance of XML_RPC_Value * it will be used as provided. It follows that, in situations when XML_RPC_Value::createFromNative * proves inacurate -- as when encoding DateTime values -- you should present an instance of * XML_RPC_Value in lieu of the native parameter. * * @param string Method name * @param array Parameters * @return mixed The call result, already decoded into native types */ public function __call($methodName, $parameters) { $args = array($methodName, $parameters); return @call_user_func_array( array($this, 'remoteCall'), $args ); } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Exception.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Exception.php +++ pear/XML_RPC2/XML/RPC2/Exception.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC2 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** * XML_RPC2 base exception class. All XML_RPC2 originated exceptions inherit from XML_RPC2_Exception * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Exception extends Exception { } /* Encoding and decoding values exceptions {{{ /** * XML_RPC2_InvalidTypeException is thrown whenever an invalid XML_RPC type is used in an operation * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_InvalidTypeException extends XML_RPC2_Exception { } /** * XML_RPC2_InvalidTypeException is thrown when creating DateTime value objects from invalid string datetime representations * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_InvalidDateFormatException extends XML_RPC2_Exception { } /** * XML_RPC2_EncodeException is thrown whenever a class is asked to encode itself in XML with invalid or not enough data. * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_EncodeException extends XML_RPC2_Exception { } /** * XML_RPC2_DecodeException is thrown whenever there is a problem decoding transport XML * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_DecodeException extends XML_RPC2_Exception { } /** * XML_RPC2_InvalidTypeEncodeException is thrown whenever a class is asked to encode itself and provided a PHP type * that can't be translated to XML_RPC * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_InvalidTypeEncodeException extends XML_RPC2_Exception { } /* }}} */ /** * XML_RPC2_InvalidUriException is thrown whenever the XML_RPC2 client is asked to use an invalid uri * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_InvalidUriException extends XML_RPC2_Exception { } /** * XML_RPC2_FaultException signals a XML-RPC response that contains a fault element instead of a regular params element. * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_FaultException extends XML_RPC2_Exception { /* vars {{{ */ protected $faultCode = null; /* }}} */ /* constructor {{{ */ /** Construct a new XML_RPC2_FaultException with a given message string and fault code * * @param string The message string, corresponding to the faultString present in the response body * @param string The fault code, corresponding to the faultCode in the response body */ function __construct($messageString, $faultCode) { parent::__construct($messageString); $this->faultCode = $faultCode; } /* }}} */ /* getFaultCode {{{ */ /** * faultCode getter */ public function getFaultCode() { return $this->faultCode; } /* }}} */ /* createFromDecode {{{ */ public static function createFromDecode($xml) { require_once 'XML/RPC2/Backend/Php/Value.php'; // This is the only way I know of creating a new Document rooted in the provided simpleXMLFragment (needed for the xpath expressions that does not segfault sometimes $xml = simplexml_load_string($xml->asXML()); $struct = XML_RPC2_Backend_Php_Value::createFromDecode($xml->value)->getNativeValue(); if (!(is_array($struct) && array_key_exists('faultString', $struct) && array_key_exists('faultCode', $struct))) throw new XML_RPC2_DecodeException('Unable to decode XML-RPC fault payload'); return new XML_RPC2_FaultException( $struct['faultString'], $struct['faultCode'] ); } /* }}} */ } /** * XML_RPC2_UnknownMethodException is thrown when a non-existent method is remote-called * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_UnknownMethodException extends XML_RPC2_Exception { } /** * XML_RPC2_TransportException signal transport level exceptions that stop requests from reaching the server * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_TransportException extends XML_RPC2_Exception { } /** * XML_RPC2_ReceivedInvalidStatusCodeExceptionextends is thrown whenever the XML_RPC2 response to a request does not return a 200 http status code. * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_ReceivedInvalidStatusCodeException extends XML_RPC2_TransportException { } /** * XML_RPC2_CurlError is thrown whenever an error is reported by the low level HTTP cURL library * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_CurlException extends XML_RPC2_TransportException { } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Server.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Server.php +++ pear/XML_RPC2/XML/RPC2/Server.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend.php'; /* }}} */ /** * XML_RPC2_Server is the frontend class for exposing PHP functions via XML-RPC. * * Exporting a programatic interface via XML-RPC using XML_RPC2 is exceedingly easy: * * The first step is to assemble all methods you wish to export into a class. You may either * create a (abstract) class with exportable methods as static, or use an existing instance * of an object. * * You'll then need to document the methods using PHPDocumentor tags. XML_RPC2 will use the * documentation for server introspection. You'll get something like this: * * <code> * class ExampleServer { * /** * * hello says hello * * * * @param string Name * * @return string Greetings * {@*} * public static function hello($name) { * return "Hello $name"; * } * } * </code> * * Now, instantiate the server, using the Factory method to select a backend and a call handler for you: * <code> * require_once 'XML/RPC2/Server.php'; * $server = XML_RPC2_Server::create('ExampleServer'); * $server->handleCall(); * </code> * * This will create a server exporting all of the 'ExampleServer' class' methods. If you wish to export * instance methods as well, pass an object instance to the factory instead: * <code> * require_once 'XML/RPC2/Server.php'; * $server = XML_RPC2_Server::create(new ExampleServer()); * $server->handleCall(); * </code> * */ abstract class XML_RPC2_Server { /* callHandler Field {{{ */ /** The call handler is responsible for executing the server exported methods */ protected $_callHandler = null; /** * callHandler setter * * @param object Object that will receive calls for remote methods */ protected function setCallHandler($callHandler) { $this->_callHandler = $callHandler; } /** * callHandler getter * * @return object Object that will receive calls for remote methods */ protected function getCallHandler() { return $this->_callHandler; } /* }}} */ /* aliases Field {{{ */ /** Holds method aliases */ protected $_aliases = array(); /** aliases setter */ protected function setAliases($aliases) { $this->_aliases = $aliases; } /** aliases appender */ protected function addAlias($alias) { $this->_aliases[] = $alias; } /** aliases getter */ protected function getAliases() { return $this->_aliases; } /* }}} */ /* Constructor {{{ */ /** * Create a new XML-RPC Server. * * @param object Call handler. The call handler will receive a method call for each remote call received. */ protected function __construct($callHandler) { $this->_callHandler = $callHandler; } /* }}} */ /* create {{{ */ /** * Factory method to select a backend and return a new XML_RPC2_Server based on the backend * * @param mixed Call target. Either a class name or an object instance. * @param string Method prefix. This prefix will be prepended to exported method names. (Defaults to '') * @param object Call handler object. Defaults to selecting a CallHandler suited to the received call target * * @return XML_RPC2_Server A server class instance */ public static function create($callTarget, $prefix = '', $callHandler = null) { $backend = XML_RPC2_Backend::getServerClassname(); // Find callHandler class if (is_null($callHandler)) { if (is_object($callTarget)) { // Delegate calls to instance methods require_once 'XML/RPC2/Server/CallHandler/Instance.php'; $callHandler = new XML_RPC2_Server_CallHandler_Instance($callTarget, $prefix); } else { // Delegate calls to static class methods require_once 'XML/RPC2/Server/CallHandler/Class.php'; $callHandler = new XML_RPC2_Server_CallHandler_Class($callTarget, $prefix); } } return new $backend($callHandler); } /* }}} */ /* handleCall(abstract) {{{ */ /** * Receive the XML-RPC request, decode the HTTP payload, delegate execution to the call handler, and output the encoded call handler response. * */ public abstract function handleCall(); /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Value.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Value.php +++ pear/XML_RPC2/XML/RPC2/Value.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend.php'; /* }}} */ /** * XML_RPC value abstract class. All XML_RPC value classes inherit from XML_RPC2_Value * * @author Sérgio Carvalho * @package XML_RPC2 */ abstract class XML_RPC2_Value { /* createFromNative {{{ */ /** * Factory method that constructs the appropriate XML-RPC encoded type value * * @param mixed Value to be encode * @param string (optional) Explicit XML-RPC type as enumerated in the XML-RPC spec (defaults to automatically selected type) * @return mixed The encoded value */ public static function createFromNative($value, $explicitType = null) { return @call_user_func(array(XML_RPC2_Backend::getValueClassname(), 'createFromNative'), $value, $explicitType); } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Client.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Client.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Client.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Util/HTTPRequest.php'; require_once 'XML/RPC2/Value.php'; require_once 'XML/RPC2/Client.php'; require_once 'XML/RPC2/Backend/Php/Request.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; /* }}} /* /** * XML_RPC client backend class. This is the default, all-php XML_RPC client backend. * * This backend does not require the xmlrpc extension to be compiled in. It implements * XML_RPC based on the always present DOM and SimpleXML PHP5 extensions. * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Client extends XML_RPC2_Client { /* constructor {{{ */ /** * Construct a new XML_RPC2_Client PHP Backend. * * To create a new XML_RPC2_Client, a URI must be provided (e.g. http://xmlrpc.example.com/1.0/). * Optionally, a prefix may be set, wich will be prepended to method names, before calling. * Prefixes are extremely useful namely when method names contain a period '.' turning them invalid * under PHP syntax. * * @param string URI for the XML-RPC server * @param string (optional) Prefix to prepend on all called functions * @param string (optional) Proxy server URI * */ function __construct($uri, $prefix = '', $proxy = null) { parent::__construct($uri, $prefix, $proxy); } /* }}} */ /* remoteCall {{{ */ /** * remoteCall executes the XML-RPC call, and returns the result * * @param string Method name * @param array Parameters */ public function remoteCall($methodName, $parameters) { $request = new XML_RPC2_Backend_Php_Request($this->getPrefix() . $methodName); $request->setParameters($parameters); $request = $request->encode(); $uri = $this->getUri(); $httpRequest = new XML_RPC2_Util_HTTPRequest($uri); $httpRequest->setPostData($request); $httpRequest->sendRequest(); return XML_RPC2_Backend_Php_Response::decode(simplexml_load_string($httpRequest->getBody())); } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Request.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Request.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Request.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 * @author Sergio Carvalho <sergio.carvalho@portugalmail.com> */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value.php'; /* }}} /* /** * XML_RPC request backend class. This class represents an XML_RPC request, exposing the methods * needed to encode/decode a request. * * @author Sergio Carvalho <sergio.carvalho@portugalmail.com> * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Request { /* Fields {{{ */ /** Name of requested method */ protected $_methodName = ''; /** Request parameters */ protected $_parameters = null; /* }}} */ /* setMethodName {{{ */ /** * methodName property setter * * @param mixed value The new methodName */ protected function setMethodName($value) { $this->_methodName = $value; } /* }}} */ /* getMethodName {{{ */ /** * methodName property getter * * @return mixed The current methodName */ public function getMethodName() { return $this->_methodName; } /* }}} */ /* setParameters {{{ */ /** * parameters property setter * * @param mixed value The new parameters */ public function setParameters($value) { $this->_parameters = $value; } /* }}} */ /* addParameter {{{ */ /** * parameters property appender * * @param mixed value The new parameter */ public function addParameter($value) { $this->_parameters[] = $value; } /* }}} */ /* getParameters {{{ */ /** * parameters property getter * * @return mixed The current parameters */ public function getParameters() { return $this->_parameters; } /* }}} */ /* constructor {{{ */ /** * Create a new xml-rpc request with the provided methodname * * @param string Name of method targeted by this xml-rpc request */ function __construct($methodName) { $this->setMethodName($methodName); $this->setParameters(array()); } /* }}} */ /* encode {{{ */ /** * Encode the request for transmission. * * @return string XML-encoded request (a full XML document) */ public function encode() { $methodName = $this->getMethodName(); $parameters = $this->getParameters(); $result = '<?xml version="1.0"?>'; $result .= '<methodCall>'; $result .= "<methodName>${methodName}</methodName>"; $result .= '<params>'; foreach($parameters as $parameter) { $result .= '<param><value>'; $result .= ($parameter instanceof XML_RPC2_Backend_Php_Value) ? $parameter->encode() : XML_RPC2_Backend_Php_Value::createFromNative($parameter)->encode(); $result .= '</value></param>'; } $result .= '</params>'; $result .= '</methodCall>'; return $result; } /* }}} */ /* createFromDecode {{{ */ /** * Decode a request from XML and construct a request object with the createFromDecoded values * * @param SimpleXMLElement The encoded XML-RPC request. * @return XML_RPC2_Backend_Php_Request The xml-rpc request, represented as an object instance */ public static function createFromDecode($simpleXML) { $methodName = (string) $simpleXML->methodName; $params = array(); foreach ($simpleXML->params->param as $param) { foreach ($param->value as $value) { $params[] = XML_RPC2_Backend_Php_Value::createFromDecode($value)->getNativeValue(); } } $result = new XML_RPC2_Backend_Php_Request($methodName); $result->setParameters($params); return $result; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Response.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Response.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Response.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value.php'; require_once 'XML/RPC2/Backend/Php/Value/Struct.php'; /* }}} /* /** * XML-RPC response backend class. * * This class represents an XML_RPC request, exposing the methods * needed to encode/decode an xml-rpc response. * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Response { /* encode {{{ */ /** * Encode a normal XML-RPC response, containing the provided value * * You may supply a php-native value, or an XML_RPC2_Backend_Php_Value instance, to be returned. Usually providing a native value * is more convenient. However, for some types, XML_RPC2_Backend_Php_Value::createFromNative can't properly choose the xml-rpc * type. In these cases, constructing an XML_RPC2_Backend_Php_Value and using it as param here is the only way to return the desired * type. * * @see http://www.xmlrpc.com/spec * @see XML_RPC2_Backend_Php_Value::createFromNative * @param mixed The result value which the response will envelop * @return string The XML payload */ public static function encode($param) { if (!$param instanceof XML_RPC2_Backend_Php_Value) { $param = XML_RPC2_Backend_Php_Value::createFromNative($param); } ob_start(); print('<?xml version="1.0"?>'); ?> <methodResponse><params><param><value><?= $param->encode() ?></value></param></params></methodResponse><?php $result = ob_get_contents(); ob_end_clean(); return $result; } /* }}} */ /* encodeFault {{{ */ /** * Encode a fault XML-RPC response, containing the provided code and message * * @see http://www.xmlrpc.com/spec * @param int Response code * @param string Response message * @return string The XML payload */ public static function encodeFault($code, $message) { $value = new XML_RPC2_Backend_Php_Value_Struct(array('faultCode' => (int) $code, 'faultString' => (string) $message)); ob_start(); print('<?xml version="1.0"?>'); ?> <methodResponse><fault><value><?= $value->encode() ?></value></fault></methodResponse><?php $result = ob_get_contents(); ob_end_clean(); return $result; } /* }}} */ /* decode {{{ */ /** * Parse a response and either return the native PHP result. * * This method receives an XML-RPC response document, in SimpleXML format, decodes it and returns the payload value. * * @param SimpleXmlElement The Transport XML * @return mixed The response payload * * @see http://www.xmlrpc.com/spec * @throws XML_RPC2_FaultException Signals the decoded response was an XML-RPC fault * @throws XML_RPC2_DecodeException Signals an ill formed payload response section */ public static function decode(SimpleXMLElement $xml) { $faultNode = $xml->xpath('/methodResponse/fault'); if (count($faultNode) == 1) { throw XML_RPC2_FaultException::createFromDecode($faultNode[0]); } $paramValueNode = $xml->xpath('/methodResponse/params/param/value'); if (count($paramValueNode) == 1) { return XML_RPC2_Backend_Php_Value::createFromDecode($paramValueNode[0])->getNativeValue(); } throw new XML_RPC2_DecodeException('Unable to decode xml-rpc response. No fault nor params/param elements found'); } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Server.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Server.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Server.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Backend/Php/Request.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; require_once 'XML/RPC2/Exception.php'; /* }}} */ /** * XML_RPC server class PHP-only backend. * * The XML_RPC2_Server does the work of decoding and encoding xml-rpc request and response. The actual * method execution is delegated to the call handler instance. * * The XML_RPC server is responsible for decoding the request and calling the appropriate method in the * call handler class. It then encodes the result into an XML-RPC response and returns it to the client. * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Server extends XML_RPC2_Server { /* Constructor {{{ */ /** * Create a new XML-RPC Server. * * The constructor receives only one parameter: the Call Handler. The call handler executes the actual * method call. XML_RPC2 server acts as a protocol decoder/encoder between the call handler and the client */ function __construct($callHandler) { parent::__construct($callHandler); } /* }}} */ /* errorToException {{{ */ public static function errorToException($errno, $errstr, $errfile, $errline) { switch ($errno) { case E_WARNING: case E_NOTICE: case E_USER_WARNING: case E_USER_NOTICE: case E_STRICT: // Silence warnings // TODO Logging should occur here break; default: throw new Exception('PHP error reported "' . $errstr . '" on ' . $errfile . ':' . $errline); } } /* }}} */ /* handleCall {{{ */ /** * Respond to the XML-RPC request. * * handleCall reads the XML-RPC request from the raw HTTP body and decodes it. It then calls the * corresponding method in the call handler class, returning the encoded result to the client. */ public function handleCall() { try { $oldErrorHandler = set_error_handler(array('XML_RPC2_Backend_Php_Server', 'errorToException')); $request = @simplexml_load_string($GLOBALS['HTTP_RAW_POST_DATA']); if (!is_object($request)) throw new XML_RPC2_FaultException('Unable to parse request XML', 0); $request = XML_RPC2_Backend_Php_Request::createFromDecode($request); $method = $request->getMethodName(); if (array_key_exists($method, $this->getAliases())) { $method = $this->_aliases[$method]; } $arguments = $request->getParameters(); print(XML_RPC2_Backend_Php_Response::encode(call_user_func_array(array($this->getCallHandler(), $method), $arguments))); if ($oldErrorHandler !== FALSE) set_error_handler($oldErrorHandler); } catch (XML_RPC2_FaultException $e) { print(XML_RPC2_Backend_Php_Response::encodeFault($e->getFaultCode(), $e->getMessage())); } catch (Exception $e) { print(XML_RPC2_Backend_Php_Response::encodeFault(1, 'Unhandled ' . get_class($e) . ' exception:' . $e->getMessage())); } } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Value.php'; /* }}} */ /** * XML_RPC value abstract class. All XML_RPC value classes inherit from XML_RPC2_Value * * @author Sérgio Carvalho * @package XML_RPC2 */ abstract class XML_RPC2_Backend_Php_Value extends XML_RPC2_Value { /* createFromNative {{{ */ /** * Choose a XML_RPC2_Value subclass appropriate for the * given value and create it. * * This method tries to find the most adequate XML-RPC datatype to hold * a given PHP native type. Note that distinguishing some datatypes may be * difficult: * - Timestamps are represented by PHP integers, so an XML_RPC2_Value_Datetime is never returned * - Indexed arrays and associative arrays are the same native PHP type. In this case: * a) The array's indexes start at 0 or 1 and increase monotonically with step 1, or * b) they do not * in the first case, an XML_RPC2_Value_Array is returned. In the second, a XML_RPC2_Value_Struct is returned. * - PHP Objects are serialized and represented in an XML_RPC2_Value_Base64 * * Whenever native object automatic detection proves inaccurate, use XML_RPC2_Value::createFromNative providing * a valid explicit type as second argument * * the appropriate XML_RPC2_Value child class instead. * * @param mixed The native value * @param string The xml-rpc target encoding type, as per the xmlrpc spec (optional) * @throws XML_RPC2_InvalidTypeEncodeException When the native value has a type that can't be translated to XML_RPC * @return A new XML_RPC2_Value instance * @see XML_RPC_Client::__call * @see XML_RPC_Server */ public static function createFromNative($nativeValue, $explicitType = null) { if (is_null($explicitType)) { switch (gettype($nativeValue)) { case 'boolean': $explicitType = 'boolean'; break; case 'integer': $explicitType = 'int'; break; case 'double': $explicitType = 'double'; break; case 'string': $explicitType = 'string'; break; case 'array': $explicitType = 'array'; $keys = array_keys($nativeValue); if (($keys[0] !== 0) && ($keys[0] !== 1)) $explicitType = 'struct'; $i=0; do { $previous = $keys[$i]; $i++; if (array_key_exists($i, $keys) && ($keys[$i] !== $keys[$i - 1] + 1)) $explicitType = 'struct'; } while (array_key_exists($i, $keys) && $explicitType == 'array'); break; case 'object': $nativeValue = serialize($nativeValue); $explicitType = 'base64'; break; case 'resource': case 'NULL': case 'unknown type': throw new XML_RPC2_InvalidTypeEncodeException(sprintf('Impossible to encode value \'%s\' from type \'%s\'. No analogous type in XML_RPC.', (string) $nativeValue, gettype($nativeValue))); default: throw new XML_RPC2_InvalidTypeEncodeException(sprintf('Unexpected PHP native type returned by gettype: \'%s\', for value \'%s\'', gettype($nativeValue), (string) $nativeValue)); } } $explicitType = ucfirst(strtolower($explicitType)); switch ($explicitType) { case 'I4': case 'Int': case 'Boolean': case 'Double': case 'String': require_once 'XML/RPC2/Backend/Php/Value/Scalar.php'; return XML_RPC2_Backend_Php_Value_Scalar::createFromNative($nativeValue); break; case 'Datetime.iso8601': require_once 'XML/RPC2/Backend/Php/Value/Datetime.php'; return new XML_RPC2_Backend_Php_Value_Datetime($nativeValue); break; case 'Base64': require_once 'XML/RPC2/Backend/Php/Value/Base64.php'; return new XML_RPC2_Backend_Php_Value_Base64($nativeValue); break; case 'Array': require_once 'XML/RPC2/Backend/Php/Value/Array.php'; return new XML_RPC2_Backend_Php_Value_Array($nativeValue); break; case 'Struct': require_once 'XML/RPC2/Backend/Php/Value/Struct.php'; return new XML_RPC2_Backend_Php_Value_Struct($nativeValue); break; default: throw new XML_RPC2_InvalidTypeEncodeException(sprintf('Unexpected explicit encoding type \'%s\'', $explicitType)); } } /* }}} */ /* createFromDecode {{{ */ /** * Decode an encoded value and build the applicable XML_RPC2_Value subclass * * @param SimpleXMLElement The encoded XML-RPC value, */ public static function createFromDecode($simpleXML) { // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when // xpath is used both in an element and in one of its children $simpleXML = simplexml_load_string($simpleXML->asXML()); $valueType = $simpleXML->xpath('./*'); if (count($valueType) == 1) { // Usually we must check the node name $nodename = dom_import_simplexml($valueType[0])->nodeName; switch ($nodename) { case 'i4': case 'int': $nativeType = 'Integer'; break; case 'boolean': $nativeType = 'Boolean'; break; case 'double': $nativeType = 'Double'; break; case 'string': $nativeType = 'String'; break; case 'dateTime.iso8601': $nativeType = 'Datetime'; break; case 'base64': $nativeType = 'Base64'; break; case 'array': $nativeType = 'Array'; break; case 'struct': $nativeType = 'Struct'; break; default: throw new XML_RPC2_DecodeException(sprintf('Unable to decode XML-RPC value. Value type is not recognized \'%s\'', $nodename)); } } elseif (count($valueType) == 0) { // Default type is string $nativeType = 'String'; } else { throw new XML_RPC2_DecodeException(sprintf('Unable to decode XML-RPC value. Value presented %s type nodes: %s.', count($valueType), $simpleXML->asXML())); } require_once(sprintf('XML/RPC2/Backend/Php/Value/%s.php', $nativeType)); $nativeType = 'XML_RPC2_Backend_Php_Value_' . $nativeType; return self::createFromNative(@call_user_func(array($nativeType, 'decode'), $simpleXML), $nodename); } /* }}} */ /* encode(abstract) {{{ */ /** * Encode the instance into XML, for transport * * @return string The encoded XML-RPC value, */ public abstract function encode(); /* }}} */ /* decode(abstract) {{{ */ /** * decode. Decode transport XML and set the instance value accordingly * * @param mixed The encoded XML-RPC value, */ public abstract static function decode($xml); /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Array.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Array.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Array.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value.php'; /* }}} */ /** * XML_RPC array value class. Represents values of type array * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Value_Array extends XML_RPC2_Backend_Php_Value { /* Fields {{{ */ /** The native value of this scalar instance */ /* setNativeValue {{{ */ /** * nativeValue property setter * * @param mixed value The new nativeValue */ protected function setNativeValue($value) { if (!is_array($value)) { throw new XML_RPC2_InvalidTypeException(sprintf('Cannot create XML_RPC2_Value_Array from type \'%s\'.', gettype($nativeValue))); } $this->_nativeValue = $value; } /* }}} */ /* getNativeValue {{{ */ /** * nativeValue property getter * * @return mixed The current nativeValue */ public function getNativeValue() { return $this->_nativeValue; } /* }}} */ protected $_nativeValue = null; /* }}} */ /* Constructor {{{ */ /** * Constructor. Will build a new XML_RPC2_Backend_Php_Value_Array with the given nativeValue * * @param mixed nativeValue */ public function __construct($nativeValue) { $this->setNativeValue($nativeValue); } /* }}} */ /* createFromDecode {{{ */ /** * Decode an encoded value and build the applicable XML_RPC2_Value subclass * * @param string The encoded XML-RPC value, */ public static function createFromDecode($encodedString) { } /* }}} */ /* encode {{{ */ /** * Encode the instance into XML, for transport * * @return string The encoded XML-RPC value, */ public function encode() { $result = '<array><data>'; foreach($this->getNativeValue() as $element) { $result .= '<value>'; $result .= ($element instanceof XML_RPC2_Backend_Php_Value) ? $element->encode() : XML_RPC2_Backend_Php_Value::createFromNative($element)->encode(); $result .= '</value>'; } $result .= '</data></array>'; return $result; } /* }}} */ /* decode {{{ */ /** * decode. Decode transport XML and set the instance value accordingly * * @param mixed The encoded XML-RPC value, */ public static function decode($xml) { // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when // xpath is used both in an element and in one of its children $xml = simplexml_load_string($xml->asXML()); $values = $xml->xpath('/value/array/data/value'); $result = array(); foreach (array_keys($values) as $i) { $result[] = XML_RPC2_Backend_Php_Value::createFromDecode($values[$i])->getNativeValue(); } return $result; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Base64.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Base64.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Base64.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value/Scalar.php'; /* }}} */ /** * XML_RPC base64 value class. Instances of this class represent base64-encoded string scalars in XML_RPC * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Value_Base64 extends XML_RPC2_Backend_Php_Value_Scalar { /* Constructor {{{ */ /** * Constructor. Will build a new XML_RPC2_Backend_Php_Value_Base64 with the given value * * This class handles encoding-decoding internally. Do not provide the * native string base64-encoded * * @param mixed String to be transmited base64-encoded */ public function __construct($nativeValue) { $this->setScalarType('base64'); $this->setNativeValue($nativeValue); } /* }}} */ /* encode {{{ */ /** * Encode the instance into XML, for transport * * @return string The encoded XML-RPC value, */ public function encode() { return '<' . $this->getScalarType() . '>' . base64_encode($this->getNativeValue()) . '</' . $this->getScalarType() . '>'; } /* }}} */ /* decode {{{ */ /** * decode. Decode transport XML and set the instance value accordingly * * @param mixed The encoded XML-RPC value, */ public static function decode($xml) { // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when // xpath is used both in an element and in one of its children $xml = simplexml_load_string($xml->asXML()); $value = $xml->xpath('/value/base64/text()'); if (!array_key_exists(0, $value)) { $value = $xml->xpath('/value/text()'); } return base64_decode($value[0]); } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Boolean.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Boolean.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Boolean.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value/Scalar.php'; /* }}} */ /** * XML_RPC boolean value class. Instances of this class represent boolean scalars in XML_RPC * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Value_Boolean extends XML_RPC2_Backend_Php_Value_Scalar { /* Constructor {{{ */ /** * Constructor. Will build a new XML_RPC2_Value_Boolean with the given value * * @param mixed value */ public function __construct($nativeValue) { parent::__construct('boolean', $nativeValue); } /* }}} */ /* encode {{{ */ /** * Encode the instance into XML, for transport * * @return string The encoded XML-RPC value, */ public function encode() { return '<' . $this->getScalarType() . '>' . ($this->getNativeValue() ? 1 : 0). '</' . $this->getScalarType() . '>'; } /* }}} */ /* decode {{{ */ /** * decode. Decode transport XML and set the instance value accordingly * * @param mixed The encoded XML-RPC value, */ public static function decode($xml) { // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when // xpath is used both in an element and in one of its children $xml = simplexml_load_string($xml->asXML()); $value = $xml->xpath('/value/boolean/text()'); return (boolean) $value[0]; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Datetime.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Datetime.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Datetime.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value/Scalar.php'; /* }}} */ /** * XML_RPC datetime value class. Instances of this class represent datetime scalars in XML_RPC * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Value_Datetime extends XML_RPC2_Backend_Php_Value_Scalar { /* Constructor {{{ */ /** * Constructor. Will build a new XML_RPC2_Backend_Php_Value_Datetime with the given value * * The provided value can be an int, which will be interpreted as a Unix timestamp, or * a string in iso8601 format * * @param mixed value * @see http://www.w3.org/TR/NOTE-datetime */ public function __construct($nativeValue) { $this->setScalarType('dateTime.iso8601'); if (gettype($nativeValue) == 'string') { if (!preg_match('/([0-9]{4})(-?([0-9]{2})(-?([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?/', $nativeValue, $matches)) { throw new XML_RPC2_InvalidDateFormatException(sprintf('Provided date \'%s\' is not ISO-8601.', $nativeValue)); } else { $year = $matches[1]; $month = array_key_exists(3, $matches) ? $matches[3] : 1; $day = array_key_exists(5, $matches) ? $matches[5] : 1; $hour = array_key_exists(7, $matches) ? $matches[7] : 0; $minutes = array_key_exists(8, $matches) ? $matches[8] : 0; $seconds = array_key_exists(10, $matches) ? $matches[10] : 0; $milliseconds = array_key_exists(12, $matches) ? ((double) ('0.' . $matches[12])) : 0; $tzSeconds = array_key_exists(13, $matches) ? ($matches[13] == 'Z' ? 0 : ($matches[15] == '-' ? -1 : 1) * (((int) $matches[16]) * 3600 + ((int) $matches[17]) * 60)) : 0; $this->setNativeValue( ((double) @gmmktime($hour, $minutes, $seconds, $month, $day, $year, 0)) + ((double) $milliseconds) - ((double) $tzSeconds)); } } else { $this->setNativeValue($nativeValue); } } /* }}} */ /* decode {{{ */ /** * decode. Decode transport XML and set the instance value accordingly * * @param mixed The encoded XML-RPC value, */ public static function decode($xml) { // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when // xpath is used both in an element and in one of its children $xml = simplexml_load_string($xml->asXML()); $value = $xml->xpath('/value/dateTime.iso8601/text()'); if (!array_key_exists(0, $value)) { $value = $xml->xpath('/value/text()'); } return (string) $value[0]; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Double.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Double.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Double.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value/Scalar.php'; /* }}} */ /** * XML_RPC double value class. Instances of this class represent int scalars in XML_RPC * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Value_Double extends XML_RPC2_Backend_Php_Value_Scalar { /* Constructor {{{ */ /** * Constructor. Will build a new XML_RPC2_Backend_Php_Value_Double with the given value * * @param mixed value */ public function __construct($nativeValue) { $this->setScalarType('double'); $this->setNativeValue($nativeValue); } /* }}} */ /* decode {{{ */ /** * decode. Decode transport XML and set the instance value accordingly * * @param mixed The encoded XML-RPC value, */ public static function decode($xml) { // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when // xpath is used both in an element and in one of its children $xml = simplexml_load_string($xml->asXML()); $value = $xml->xpath('/value/double/text()'); return (double) $value[0]; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Integer.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Integer.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Integer.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value/Scalar.php'; /* }}} */ /** * XML_RPC integer value class. Instances of this class represent int scalars in XML_RPC * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Value_Integer extends XML_RPC2_Backend_Php_Value_Scalar { /* Constructor {{{ */ /** * Constructor. Will build a new XML_RPC2_Backend_Php_Value_Integer with the given value * * @param mixed value */ public function __construct($nativeValue) { $this->setScalarType('int'); $this->setNativeValue($nativeValue); } /* }}} */ /* decode {{{ */ /** * decode. Decode transport XML and set the instance value accordingly * * @param mixed The decoded XML-RPC value, */ public static function decode($xml) { // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when // xpath is used both in an element and in one of its children $xml = simplexml_load_string($xml->asXML()); $value = $xml->xpath('/value/int/text()|/value/i4/text()'); return (int) $value[0]; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Scalar.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Scalar.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Scalar.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value.php'; /* }}} */ /** * XML_RPC scalar value abstract class. All XML_RPC value classes representing scalar types inherit from XML_RPC2_Value_Scalar * * @author Sérgio Carvalho * @package XML_RPC2 */ abstract class XML_RPC2_Backend_Php_Value_Scalar extends XML_RPC2_Backend_Php_Value { /* Fields {{{ */ /** The native type of this scalar instance as per XML_RPC spec */ /* setScalarType {{{ */ /** * scalarType property setter * * @param mixed value The new scalarType */ protected function setScalarType($value) { switch ($value) { case 'int': case 'i4': case 'boolean': case 'string': case 'double': case 'dateTime.iso8601': case 'base64': $this->_scalarType = $value; break; default: throw new XML_RPC2_InvalidTypeException(sprintf('Type \'%s\' is not an XML-RPC scalar type', $value)); } } /* }}} */ /* getScalarType {{{ */ /** * scalarType property getter * * @return mixed The current scalarType */ public function getScalarType() { return $this->_scalarType; } /* }}} */ protected $_scalarType = null; /** The native value of this scalar instance */ /* setNativeValue {{{ */ /** * nativeValue property setter * * @param mixed value The new nativeValue */ protected function setNativeValue($value) { $this->_nativeValue = $value; } /* }}} */ /* getNativeValue {{{ */ /** * nativeValue property getter * * @return mixed The current nativeValue */ public function getNativeValue() { return $this->_nativeValue; } /* }}} */ protected $_nativeValue = null; /* }}} */ /* Constructor {{{ */ /** * Constructor. Will build a new XML_RPC2_Value_Scalar with the given nativeValue * * @param mixed nativeValue */ public function __construct($scalarType, $nativeValue) { $this->setScalarType($scalarType); $this->setNativeValue($nativeValue); } /* }}} */ /* createFromNative {{{ */ /** * Choose a XML_RPC2_Value subclass appropriate for the * given value and create it. * * @param string The native value * @param string Optinally, the scalar type to use * @throws XML_RPC2_InvalidTypeEncodeException When native value's type is not a native type * @return XML_RPC2_Value The newly created value */ public static function createFromNative($nativeValue, $explicitType = null) { if (is_null($explicitType)) { switch (gettype($nativeValue)) { case 'boolean': case 'integer': case 'double': case 'string': $explicitType = gettype($nativeValue); break; default: throw new XML_RPC2_InvalidTypeEncodeException(sprintf('Impossible to encode scalar value \'%s\' from type \'%s\'. Native type is not a scalar XML_RPC type (boolean, integer, double, string)', (string) $nativeValue, gettype($nativeValue))); } } $explicitType = ucfirst(strtolower($explicitType)); require_once(sprintf('XML/RPC2/Backend/Php/Value/%s.php', $explicitType)); $explicitType = sprintf('XML_RPC2_Backend_Php_Value_%s', $explicitType); return new $explicitType($nativeValue); } /* }}} */ /* encode {{{ */ /** * Encode the instance into XML, for transport * * @return string The encoded XML-RPC value, */ public function encode() { return '<' . $this->getScalarType() . '>' . $this->getNativeValue() . '</' . $this->getScalarType() . '>'; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value/String.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value/String.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value/String.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value/Scalar.php'; /* }}} */ /** * XML_RPC string value class. Instances of this class represent string scalars in XML_RPC * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Value_String extends XML_RPC2_Backend_Php_Value_Scalar { /* Constructor {{{ */ /** * Constructor. Will build a new XML_RPC2_Backend_Php_Value_String with the given value * * @param mixed value */ public function __construct($nativeValue) { $this->setScalarType('string'); $this->setNativeValue($nativeValue); } /* }}} */ /* encode {{{ */ /** * Encode the instance into XML, for transport * * @return string The encoded XML-RPC value, */ public function encode() { return '<' . $this->getScalarType() . '>' . strtr($this->getNativeValue(),array('&' => '&', '<' => '<' , '>' => '>')) . '</' . $this->getScalarType() . '>'; } /* }}} */ /* decode {{{ */ /** * decode. Decode transport XML and set the instance value accordingly * * @param mixed The encoded XML-RPC value, */ public static function decode($xml) { // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when // xpath is used both in an element and in one of its children $xml = simplexml_load_string($xml->asXML()); $value = $xml->xpath('/value/string/text()'); if (!array_key_exists(0, $value)) { $value = $xml->xpath('/value/text()'); } return (string) $value[0]; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Struct.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Struct.php +++ pear/XML_RPC2/XML/RPC2/Backend/Php/Value/Struct.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend/Php/Value.php'; /* }}} */ /** * XML_RPC struct value class. Represents values of type struct (associative struct) * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Php_Value_Struct extends XML_RPC2_Backend_Php_Value { /* Fields {{{ */ /** The native value of this scalar instance */ /* setNativeValue {{{ */ /** * nativeValue property setter * * @param mixed value The new nativeValue */ protected function setNativeValue($value) { if (!is_array($value)) { throw new XML_RPC2_InvalidTypeException(sprintf('Cannot create XML_RPC2_Backend_Php_Value_Struct from type \'%s\'.', gettype($nativeValue))); } $this->_nativeValue = $value; } /* }}} */ /* getNativeValue {{{ */ /** * nativeValue property getter * * @return mixed The current nativeValue */ public function getNativeValue() { return $this->_nativeValue; } /* }}} */ protected $_nativeValue = null; /* }}} */ /* Constructor {{{ */ /** * Constructor. Will build a new XML_RPC2_Backend_Php_Value_Scalar with the given nativeValue * * @param mixed nativeValue */ public function __construct($nativeValue) { $this->setNativeValue($nativeValue); } /* }}} */ /* encode {{{ */ /** * Encode the instance into XML, for transport * * @return string The encoded XML-RPC value, */ public function encode() { $result = '<struct>'; foreach($this->getNativeValue() as $name => $element) { $result .= '<member>'; $result .= '<name>'; $result .= strtr($name, array('&' => '&', '<' => '<', '>' => '>')); $result .= '</name>'; $result .= '<value>'; $result .= ($element instanceof XML_RPC2_Backend_Php_Value) ? $element->encode() : XML_RPC2_Backend_Php_Value::createFromNative($element)->encode(); $result .= '</value>'; $result .= '</member>'; } $result .= '</struct>'; return $result; } /* }}} */ /* decode {{{ */ /** * decode. Decode transport XML and set the instance value accordingly * * @param mixed The encoded XML-RPC value, */ public static function decode($xml) { // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when // xpath is used both in an element and in one of its children $xml = simplexml_load_string($xml->asXML()); $values = $xml->xpath('/value/struct/member'); $result = array(); foreach (array_keys($values) as $i) { $result[(string) $values[$i]->name] = XML_RPC2_Backend_Php_Value::createFromDecode($values[$i]->value)->getNativeValue(); } return $result; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext/Client.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext/Client.php +++ pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext/Client.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Value.php'; require_once 'XML/RPC2/Client.php'; require_once 'XML/RPC2/Backend/Php/Request.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; require_once 'XML/RPC2/Util/HTTPRequest.php'; /* }}} /* /** * XML_RPC client backend class. This backend class uses the XMLRPCext extension to execute the call. * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Xmlrpcext_Client extends XML_RPC2_Client { /* constructor {{{ */ /** * Construct a new XML_RPC2_Client PHP Backend. * * To create a new XML_RPC2_Client, a URI must be provided (e.g. http://xmlrpc.example.com/1.0/). * Optionally, a prefix may be set, wich will be prepended to method names, before calling. * Prefixes are extremely useful namely when method names contain a period '.' turning them invalid * under PHP syntax. * * @param string URI for the XML-RPC server * @param string (optional) Prefix to prepend on all called functions * @param string (optional) Proxy server URI * */ function __construct($uri, $prefix = '', $proxy = null) { parent::__construct($uri, $prefix, $proxy); } /* }}} */ /* remoteCall {{{ */ /** * remoteCall executes the XML-RPC call, and returns the result * * @param string Method name * @param array Parameters */ public function remoteCall($methodName, $parameters) { $request = xmlrpc_encode_request($this->getPrefix() . $methodName, $parameters); $uri = $this->getUri(); $httpRequest = new XML_RPC2_Util_HTTPRequest($uri); $httpRequest->setPostData($request); $httpRequest->sendRequest(); $result = xmlrpc_decode($httpRequest->getBody()); if ($result === false) { throw new XML_RPC2_Exception('Unable to decode response'); } if (xmlrpc_is_fault($result)) { throw new XML_RPC2_FaultException($result['faultString'], $result['faultCode']); } return $result; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext/Server.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext/Server.php +++ pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext/Server.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Backend/Php/Request.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; require_once 'XML/RPC2/Exception.php'; /* }}} */ /** * XML_RPC server class XMLRPCext extension-based backend * * The XML_RPC2_Server does the work of decoding and encoding xml-rpc request and response. The actual * method execution is delegated to the call handler instance. * * The XML_RPC server is responsible for decoding the request and calling the appropriate method in the * call handler class. It then encodes the result into an XML-RPC response and returns it to the client. * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Xmlrpcext_Server extends XML_RPC2_Server { /* _xmlrpcextServer Field {{{ */ private $_xmlrpcextServer; /** _xmlrpcextServer getter * * @return resource xmlrpcext server */ private function getXmlrpcextServer() { return $this->_xmlrpcextServer; } /** _xmlrpcextServer setter * * @param resource xmlrpcext server */ private function setXmlrpcextServer($server) { $this->_xmlrpcextServer = $server; } /* }}} */ /* Constructor {{{ */ /** * Create a new XML-RPC Server. * * The constructor receives only one parameter: the Call Handler. The call handler executes the actual * method call. XML_RPC2 server acts as a protocol decoder/encoder between the call handler and the client */ function __construct($callHandler) { parent::__construct($callHandler); $this->setXmlrpcextServer(xmlrpc_server_create()); foreach ($callHandler->getMethods() as $method) { if (xmlrpc_server_register_method($this->getXmlrpcextServer(), $method->getName(), array($this, 'epiFunctionHandlerAdapter')) !== true) { throw new XML_RPC2_Exception('Unable to setup XMLRPCext server. xmlrpc_server_register_method returned non-true.'); } } } /* }}} */ /* epiFunctionHandlerAdapter {{{ */ /** * This is an adapter between XML_RPC2_CallHandler::__call and xmlrpc_server_register_method callback interface * * @param string Method name * @param array Parameters * @param array Application data (ignored) */ protected function epiFunctionHandlerAdapter($method_name, $params, $app_data) { return @call_user_func_array(array($this->getCallHandler(), $method_name), $params); } /* }}} */ /* errorToException {{{ */ public static function errorToException($errno, $errstr, $errfile, $errline) { switch ($errno) { case E_WARNING: case E_NOTICE: case E_USER_WARNING: case E_USER_NOTICE: case E_STRICT: // Silence warnings // TODO Logging should occur here break; default: throw new Exception('Classic error reported "' . $errstr . '" on ' . $errfile . ':' . $errline); } } /* }}} */ /* handleCall {{{ */ /** * Respond to the XML-RPC request. * * handleCall reads the XML-RPC request from the raw HTTP body and decodes it. It then calls the * corresponding method in the call handler class, returning the encoded result to the client. */ public function handleCall() { try { $oldErrorHandler = set_error_handler(array('XML_RPC2_Backend_Xmlrpcext_Server', 'errorToException')); $response = @xmlrpc_server_call_method($this->getXmlrpcextServer(), $GLOBALS['HTTP_RAW_POST_DATA'], null, array('output_type' => 'xml')); header('Content-type: text/xml'); header('Content-length: '.strlen($response)); print $response; if ($oldErrorHandler !== FALSE) set_error_handler($oldErrorHandler); } catch (XML_RPC2_FaultException $e) { print(XML_RPC2_Backend_Php_Response::encodeFault($e->getFaultCode(), $e->getMessage())); } catch (Exception $e) { print(XML_RPC2_Backend_Php_Response::encodeFault(1, 'Unhandled ' . get_class($e) . ' exception:' . $e->getMessage())); } } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext/Value.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext/Value.php +++ pear/XML_RPC2/XML/RPC2/Backend/Xmlrpcext/Value.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Backend.php'; /* }}} */ /** * XML_RPC value class for the XMLRPCext backend. * * @author Sérgio Carvalho * @package XML_RPC2 */ class XML_RPC2_Backend_Xmlrpcext_Value { /* createFromNative {{{ */ /** * Factory method that constructs the appropriate XML-RPC encoded type value * * @param mixed Value to be encode * @param string Explicit XML-RPC type as enumerated in the XML-RPC spec (defaults to automatically selected type) * @return mixed The encoded value */ public static function createFromNative($value, $explicitType) { if (!xmlrpc_set_type($value, $explicitType)) { throw new XML_RPC2_Exception('Error returned from xmlrpc_set_type'); } return $value; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Server/CallHandler.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Server/CallHandler.php +++ pear/XML_RPC2/XML/RPC2/Server/CallHandler.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; /* }}} */ /** * A CallHandler is responsible for actually calling the server-exported methods from the exported class. * * This class is abstract and not meant to be used directly by XML_RPC2 users. * * XML_RPC2_Server_CallHandler provides the basic code for a call handler class. An XML_RPC2 Call Handler * operates in tandem with an XML_RPC2 server to export a classe's methods. While XML_RPC2 Server * is responsible for request decoding and response encoding, the Call Handler is responsible for * delegating the actual method call to the intended target. * * Different server behaviours can be obtained by plugging different Call Handlers into the XML_RPC2_Server. * Namely, there are two call handlers available: * - XML_RPC2_Server_Callhandler_Class: Which exports a classe's public static methods * - XML_RPC2_Server_Callhandler_Instance: Which exports an object's pubilc methods * * @see XML_RPC2_Server_Callhandler_Class * @see XML_RPC2_Server_Callhandler_Instance * * @package XML_RPC2 * @author Sérgio Carvalho <sergio.carvalho@portugalmail.com> */ abstract class XML_RPC2_Server_CallHandler { /* methods Field {{{ */ /** Holds server methods */ protected $_methods = array(); /** * methods setter * * @param array Array of XML_RPC2_Server_Method instances */ protected function setMethods($methods) { $this->_methods = $methods; } /** * methods getter * * @return array Array of XML_RPC2_Server_Method instances */ public function getMethods() { return $this->_methods; } /** * method appender * * @param XML_RPC2_Server_Method Method to append to _methods */ protected function addMethod(XML_RPC2_Server_Method $method) { $this->_methods[$method->getName()] = $method; } /** * method getter * * @param string Name of method to return * @param XML_RPC2_Server_Method Method named $name */ public function getMethod($name) { return $this->_methods[$name]; } /* }}} */ /* system_listMethods {{{ */ /** * Introspect server, returning method list. * * This method may be used to * enumerate the methods implemented by the XML-RPC server. The * system.listMethods method requires no parameters. It returns an array * of strings, each of which is the name of a method implemented by the * server. * * @returns array method names * */ protected static final function system_listMethods() { return array_keys($this->getMethods()); } /* }}} */ /* system_methodHelp {{{ */ /** * Introspect server, returning method help text. * * If the method does * not exist, returns false. If the method exists, but help text is * not defined, returns an empty string. * * @param string Method name whose help to return * @returns string Method help * */ protected static final function system_methodHelp($methodName) { $methods = $this->getMethods(); if (!array_key_exists($methodName, $methods)) { return false; } return $methods[$methodName]->methodHelp(); } /* }}} */ /* system_methodSignature {{{ */ /** * Introspect server, returning a method signature. * * This method takes one * parameter, the name of a method implemented by the XML-RPC server. * It returns an array of possible signatures for this method. A signature * is an array of types. The first of these types is the return type of * the method, the rest are parameters. * Even if the XML-RPC spec supports function overloading, PHP does not. * On this server, this function will either return a one-element array or * false (if the method does not exist). * * @param string Method name whose signature to return * @returns string Method help * * @xmlrpc.prefix system. * */ protected static final function system_methodSignature($methodName) { $methods = $this->getMethods(); if (!array_key_exists($methodName, $methods)) { return false; } return array($methods[$methodName]->methodSignature()); } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Server/Method.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Server/Method.php +++ pear/XML_RPC2/XML/RPC2/Server/Method.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * XML_RPC2_Server_Method * * @package XML_RPC2 * @author Sergio Carvalho <sergio.carvalho@portugalmail.com> **/ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; /* }}} */ /** * Class representing an XML-RPC exported method. * * This class is used internally by XML_RPC2_Server. External users of the * package should not need to ever instantiate XML_RPC2_Server_Method * * @package XML_RPC2 * @author Sergio Carvalho <sergio.carvalho@portugalmail.com> * @see XML_RPC2_ServerMethodHandler **/ class XML_RPC2_Server_Method { /* fields {{{ */ /** Method signature parameters */ public $parameters; /** Method signature return type */ public $returns ; /** Method help, for introspection */ public $help; /* }}} */ /* internalMethod field {{{ */ /** Method name in PHP-land */ protected $_internalMethod; /** internalMethod getter * * @return string internalMethod */ public function getInternalMethod() { return $this->_internalMethod; } /** internalMethod setter * * @param string internalMethod */ public function setInternalMethod($value) { $this->_internalMethod = $value; } /* }}} */ /* hidden field {{{ */ /** True if the method is hidden */ protected $_hidden; /** hidden getter * * @return boolean hidden value */ public function isHidden() { return $this->_hidden; } /** hidden setter * * @param boolean hidden value */ public function setHidden($hidden) { $this->_hidden = $hidden; } /* }}} */ /* name Field {{{ */ /** External method name */ protected $_name; /** * _name getter * * @return string _name */ public function getName() { return $this->_name; } /** * _name setter * * @param string _name */ public function setName($name) { $this->_name = $name; } /* }}} */ /* constructor {{{ */ /** * Create a new XML-RPC method by introspecting a PHP method * * @param ReflectionMethod The PHP method to introspect */ public function __construct(ReflectionMethod $method, $defaultPrefix) { $hidden = false; $docs = $method->getDocComment(); if (!$docs) { $hidden = true; } $docs = explode("\n", $docs); $parameters = array(); $methodname = null; $returns = 'mixed'; $shortdesc = ''; $paramcount = -1; $prefix = $defaultPrefix; // Extract info from Docblock $paramDocs = array(); foreach ($docs as $i => $doc) { $doc = trim($doc, " \r\t/*"); if (strlen($doc) && strpos($doc, '@') !== 0) { if ($shortdesc) { $shortdesc .= "\n"; } $shortdesc .= $doc; continue; } if (strpos($doc, '@xmlrpc.hidden') === 0) { $hidden = true; } if ((strpos($doc, '@xmlrpc.prefix') === 0) && preg_match('/@xmlrpc.prefix( )*(.*)/', $doc, $matches)) { $prefix = $matches[2]; } if ((strpos($doc, '@xmlrpc.methodname') === 0) && preg_match('/@xmlrpc.prefix( )*(.*)/', $doc, $matches)) { $methodname = $matches[2]; } if (strpos($doc, '@param') === 0) { // Save doctag for usage later when filling parameters $paramDocs[] = $doc; } if (strpos($doc, '@return') === 0) { $param = preg_split("/\s+/", $doc); if (isset($param[1])) { $param = $param[1]; $returns = $param; } } } // Fill in info for each method parameter foreach ($method->getParameters() as $parameterIndex => $parameter) { // Parameter defaults $newParameter = array('optional' => false, 'type' => 'mixed'); // Attempt to extract type and doc from docblock if (array_key_exists($parameterIndex, $paramDocs) && preg_match('/@param\s+(\S+)(\s+(.+))/', $paramDocs[$parameterIndex], $matches)) { if (strpos($matches[1], '|')) { $newParameter['type'] = explode('|', $matches[1]); } else { $newParameter['type'] = $matches[1]; } $newParameter['doc'] = $matches[2]; } // Attempt to extract optional status from Reflection API if (method_exists($method, 'isOptional')) { $newParameter['optional'] = $parameter->isOptional(); } // Attempt to extract type from Reflection API if ($parameter->getClass()) { $newParameter['type'] = $parameter->getClass(); } $parameters[$parameter->getName()] = $newParameter; } if (is_null($methodname)) { $methodname = $prefix . $method->getName(); } $this->setInternalMethod($method->getName()); $this->parameters = $parameters; $this->returns = $returns; $this->help = $shortdesc; $this->setName($methodname); $this->setHidden($hidden); } /* }}} */ /* matchesSignature {{{ */ /** * Check if method matches provided call signature * * Compare the provided call signature with this methods' signature and * return true iff they match. * * @param string Signature to compare method name * @param array Array of parameter values for method call. * @return boolean True if call matches signature, false otherwise */ public function matchesSignature($methodName, $callParams) { if ($methodName != $this->getName()) return false; $paramIndex = 0; foreach($this->parameters as $param) { if (!($param['optional'] || array_key_exists($paramIndex, $callParams))) { // Missing non-optional param return false; } if ((array_key_exists($paramIndex, $callParams)) && (!($param['type'] == 'mixed' || $param['type'] == gettype($callParams[$paramIndex])))) { return false; } } return true; } /* }}} */ /* autoDocument {{{ */ /** * Return HTML snippet documenting method, for XML-RPC server introspection. * * @return string HTML snippet documenting method */ public function autoDocument() { $result = '<dl><dt>Method description</dt><dd>' . $this->help . '</dd>'; $result .= '<dt>Method parameters</dt><dd><dl>'; foreach ($this->parameters as $paramName => $param) { $result .= '<dt><i>' . $param['type'] . "</i>$paramName</dt><dd>"; if ($param['optional']) $result .= '[optional]'; $result .= $param['doc']; $result .= '</dd>'; } $result .= '</dl></dd>'; $result .= '<dt>Returns</dt><dd><i>' . $this->returns . '</i></dd>'; $result .= '</dl>'; return $result; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Server/CallHandler/Class.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Server/CallHandler/Class.php +++ pear/XML_RPC2/XML/RPC2/Server/CallHandler/Class.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Server/Method.php'; require_once 'XML/RPC2/Server/CallHandler.php'; /* }}} */ /** * This class is a server call handler which exposes a classe's static public methods. * * XML_RPC2_Server_Callhandler_Class is the preferred call handler to use when you are * designing your XML-RPC server from the ground up. Usage is quite simple: * - Create a class holding all of the XML-RPC server's exported procedures as public static methods (the interface class). * - PhpDoc the classes' methods, including at least method signature (params and return types) and short description. * - Use the XML_RPC2 factory method to create a server based on the interface class. * A simple example: * <code> * /** * * echoecho echoes the message received * * * * @param string Message * * @return string The echo * {@*} * class EchoServer { * public static function echoecho($string) * { * return $string; * } * } * * require_once 'XML/RPC2/Server.php'; * $server = XML_RPC2_Server::create('EchoServer'); * $server->handleCall(); * </code> * * Use this call handler if you have designed your xml-rpc external interface as a set of * public class methods on a given class. If, on the other hand, you intend to export an * already existing class, it may be that not all of the methods you want to export are static. * In that case, it is probably best to use XML_RPC2_Server_Callhandler_Instance instead. * * @see XML_RPC2_Server::create * @see XML_RPC2_Server_Callhandler_Instance * * @package XML_RPC2 * @author Sérgio Carvalho <sergio.carvalho@portugalmail.com> */ class XML_RPC2_Server_Callhandler_Class extends XML_RPC2_Server_CallHandler { /* className field {{{ */ /** name of target class */ private $_className; /** * className setter * * @param string Class name */ public function setClassName($className) { $this->_className = $className; } /** * className getter * * @return string Class name */ public function getClassName() { return $this->_className; } /* }}} */ /* constructor {{{ */ /** * XML_RPC2_Server_Callhandler_Class Constructor. Creates a new call handler exporting the give static class' methods * * Before using this constructor, take a look at XML_RPC2_Server::create. The factory * method is usually a quicker way of instantiating the server and its call handler. * * @see XML_RPC2_Server::create() * @param string The Target class. Calls will be made on this class * @param string Default prefix to prepend to all exported methods (defaults to '') */ public function __construct($className, $defaultPrefix) { $this->setClassname($className); $reflection = new ReflectionClass($className); foreach ($reflection->getMethods() as $method) { if ($method->isStatic() && $method->isPublic() && !$method->isAbstract() && !$method->isConstructor()) { $candidate = new XML_RPC2_Server_Method($method, $defaultPrefix); if (!$candidate->isHidden()) $this->addMethod($candidate); } } } /* }}} */ /* __call {{{ */ /** * __call catchall. Delegate the method call to the target class, and return its result * * @param string Name of method to call * @param array Array of parameters for call * @return mixed Whatever the target method returned */ public function __call($methodName, $parameters) { if (!array_key_exists($methodName, $this->getMethods())) { throw new XML_RPC2_UnknownMethodException("Method $methodName is not exported by this server"); } return call_user_func_array(array($this->getClassname(), $this->getMethod($methodName)->getInternalMethod()), $parameters); } /* }}} */ } /* */ ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Server/CallHandler/Instance.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Server/CallHandler/Instance.php +++ pear/XML_RPC2/XML/RPC2/Server/CallHandler/Instance.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; require_once 'XML/RPC2/Server/Method.php'; require_once 'XML/RPC2/Server/CallHandler.php'; /* }}} */ /** * This class is a server call handler which exposes an instance's public methods. * * XML_RPC2_Server_Callhandler_Instance is the preferred call handler to use when * you just need to quickly expose an already existing object. If designing a remote * API from the ground up, it's best to use XML_RPC2_Server_Callhandler_Class instead. * * Usage is simple: * - PhpDoc the methods, including at least method signature (params and return types) and short description. * - Use the XML_RPC2 factory method to create a server based on the interface class. * A simple example: * <code> * class EchoServer { * /** * * Echo the message * * * * @param string The string to echo * * @return string The echo * {@*} * public function echoecho($string) * { * return $string; * } * } * * require_once 'XML/RPC2/Server.php'; * $someInstance = new EchoServer(); * $server = XML_RPC2_Server::create($someInstance); * $server->handleCall(); * </code> * * @see XML_RPC2_Server::create * @see XML_RPC2_Server_Callhandler_Class * * @package XML_RPC2 * @author Sérgio Carvalho <sergio.carvalho@portugalmail.com> */ class XML_RPC2_Server_Callhandler_Instance extends XML_RPC2_Server_CallHandler { /* instance field {{{ */ /** instance of target object */ private $_instance; /** * instance setter * * @param object target object instance */ public function setInstance($instance) { $this->_instance = $instance; } /** * instance getter * * @return object target object instance */ public function getInstance() { return $this->_instance; } /* }}} */ /* constructor {{{ */ /** * XML_RPC2_Server_Callhandler_Class Constructor. Creates a new call handler exporting the given object methods * * Before using this constructor, take a look at XML_RPC2_Server::create. The factory * method is usually a quicker way of instantiating the server and its call handler. * * @see XML_RPC2_Server::create() * @param object The Target object. Calls will be made on this instance * @param string Default prefix to prepend to all exported methods (defaults to '') */ public function __construct($instance, $defaultPrefix) { $this->setInstance($instance); $reflection = new ReflectionClass(get_class($instance)); foreach ($reflection->getMethods() as $method) { if (!$method->isStatic() && $method->isPublic() && !$method->isConstructor()) { $candidate = new XML_RPC2_Server_Method($method, $defaultPrefix); if (!$candidate->isHidden()) $this->addMethod($candidate); } } } /* }}} */ /* __call {{{ */ /** * __call catchall. Delegate the method call to the target object, and return its result * * @param string Name of method to call * @param array Array of parameters for call * @return mixed Whatever the target method returned */ public function __call($methodName, $parameters) { if (!array_key_exists($methodName, $this->getMethods())) { throw new XML_RPC2_UnknownMethodException("Method $methodName is not exported by this server"); } return call_user_func_array(array($this->getInstance(), $this->getMethod($methodName)->getInternalMethod()), $parameters); } /* }}} */ } /* */ ?> http://cvs.php.net/co.php/pear/XML_RPC2/XML/RPC2/Util/HTTPRequest.php?r=1.1&p=1 Index: pear/XML_RPC2/XML/RPC2/Util/HTTPRequest.php +++ pear/XML_RPC2/XML/RPC2/Util/HTTPRequest.php <?php /* LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4 foldmethod=marker: +-----------------------------------------------------------------------------+ | Copyright (c) 2004 Sérgio Gonçalves Carvalho | +-----------------------------------------------------------------------------+ | This file is part of XML_RPC2. | | | | XML_RPC 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. | | | | XML_RPC2 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 XML_RPC2; if not, write to the Free Software | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | | 02111-1307 USA | +-----------------------------------------------------------------------------+ | Author: Sérgio Carvalho <sergio.carvalho@portugalmail.com> | +-----------------------------------------------------------------------------+ }}} */ /** * @package XML_RPC2 */ /** */ /* dependencies {{{ */ require_once 'XML/RPC2/Exception.php'; /* }}} /* /** * XML_RPC utility HTTP request class. This class mimics a subset of PEAR's HTTP_Request * and is to be refactored out of the package once HTTP_Request releases an E_STRICT version. * * @package XML_RPC2 * @author Sérgio Carvalho */ class XML_RPC2_Util_HTTPRequest { /* body Field {{{ */ private $_body; /** * body field getter * * @return string body value */ public function getBody() { return $this->_body; } /** * body field setter * * @param string body value */ public function setBody($value) { $this->_body = $value; } /* }}} */ /* postData Field {{{ */ private $_postData; /** * postData field getter * * @return string postData value */ public function getPostData() { return $this->_postData; } /** * postData field setter * * @param string postData value */ public function setPostData($value) { $this->_postData = $value; } /* }}} */ /* method Field {{{ */ private $_method = 'POST'; /** * method field getter * * @return array method value */ public function getMethod() { return $this->_method; } /** * method field setter (ignored!) * * This setter is ignored, and method set to POST always. It is here for API compatibility reasons alone. * * @param array method value */ public function setMethod($value) { $this->_method = 'POST'; } /* }}} */ /* params Field {{{ */ private $_params; /** * params field getter * * @return array params value */ public function getParams() { return $this->_params; } /** * params field setter * * @param array params value */ public function setParams($value) { $this->_params = $value; } /* }}} */ /* proxy Field {{{ */ private $_proxy = null; /** * proxy field getter * * @return string proxy value */ public function getProxy() { return $this->_proxy; } /** * proxy field setter * * @param string proxy value */ public function setProxy($value) { $this->_proxy = $value; } /* }}} */ /* proxyAuth Field {{{ */ private $_proxyAuth = null; /** * proxyAuth field getter * * @return string proxyAuth value */ public function getProxyAuth() { return $this->_proxyAuth; } /** * proxyAuth field setter * * @param string proxyAuth value */ public function setProxyAuth($value) { $this->_proxyAuth = $value; } /* }}} */ /* uri Field {{{ */ private $_uri; /** * uri field getter * * @return string uri value */ public function getURI() { return $this->_uri; } /** * uri field setter * * @param string uri value */ public function setURI($value) { $this->_uri = $value; } /* }}} */ /* constructor {{{ */ /** * Constructor * * Sets up the object * @param string The uri to fetch/access * @param array Associative array of parameters which can have the following keys: * <ul> * <li>user - Basic Auth username (string)</li> * <li>pass - Basic Auth password (string)</li> * <li>proxy_host - Proxy server host (string)</li> * <li>proxy_port - Proxy server port (integer)</li> * <li>proxy_user - Proxy auth username (string)</li> * <li>proxy_pass - Proxy auth password (string)</li> * </ul> * @access public */ public function __construct($uri = '', $params = array()) { $this->setUri($uri); if (array_key_exists('user', $params) && array_key_exists('pass', $params)) { if (!preg_match('/(https?:\/\/)(.*)/', $uri, $matches)) throw new XML_RPC2_Exception('Unable to parse URI'); $uri = $matches[1] . uriencode($params['user']) . ':' . uriencode($params['pass']) . '@' . $matches[2]; } if (array_key_exists('proxy_host', $params)) { if (!array_key_exists('proxy_port', $params)) { $params['proxy_port'] = 3128; } $this->setProxy("http://{$params['proxy_host']}:{$params['proxy_port']}"); } if (array_key_exists('proxy_user', $params) && array_key_exists('proxy_pass', $params)) { $this->setProxyAuth("{$params['proxy_user']}:{$params['proxy_pass']}"); } } /* }}} */ /* sendRequest {{{ */ /** * Sends the request * * @access public * @return mixed PEAR error on error, true otherwise */ public function sendRequest() { if (!function_exists('curl_init') && !( // TODO Use PEAR::loadExtension once PEAR passes PHP5 unit tests (E_STRICT compliance, namely) @dl('php_curl' . PHP_SHLIB_SUFFIX) || @dl('curl' . PHP_SHLIB_SUFFIX) )) { throw new XML_RPC2_CurlException('cURI extension is not present and load failed'); } if ($ch = curl_init()) { if ( (is_null($this->getProxy()) || curl_setopt($ch, CURLOPT_PROXY, $this->getProxy())) && (is_null($this->getProxyAuth()) || curl_setopt($ch, CURLOPT_PROXYAUTH, $this->getProxyAuth())) && curl_setopt($ch, CURLOPT_URL, $this->getUri()) && curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE) && curl_setopt($ch, CURLOPT_POST, 1) && curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml')) && curl_setopt($ch, CURLOPT_POSTFIELDS, $this->getPostData()) ) { $result = curl_exec($ch); if (($errno = curl_errno($ch)) != 0) { throw new XML_RPC2_CurlException("Curl returned non-null errno $errno:" . curl_error($ch)); } $info = curl_getinfo($ch); if ($info['http_code'] != 200) { throw new XML_RPC2_ReceivedInvalidStatusCodeException('Curl returned non 200 HTTP code: ' . $info['http_code'] . '. Response body:' . $result); } } else { throw new XML_RPC2_CurlException('Unable to setup curl'); } } else { throw new XML_RPC2_CurlException('Unable to init curl'); } $this->setBody($result); return true; } /* }}} */ } ?> http://cvs.php.net/co.php/pear/XML_RPC2/docs/tutorials/XML_RPC2.lyx?r=1.1&p=1 Index: pear/XML_RPC2/docs/tutorials/XML_RPC2.lyx +++ pear/XML_RPC2/docs/tutorials/XML_RPC2.lyx #LyX 1.3 created this file. For more info see http://www.lyx.org/ \lyxformat 221 \textclass docbook-section \language english \inputencoding auto \fontscheme default \graphics default \paperfontsize default \spacing single \papersize Default \paperpackage a4 \use_geometry 0 \use_amsmath 0 \use_natbib 0 \use_numerical_citations 0 \paperorientation portrait \secnumdepth 3 \tocdepth 3 \paragraph_separation indent \defskip medskip \quotes_language english \quotes_times 2 \papercolumns 1 \papersides 1 \paperpagestyle default \layout Title \added_space_top vfill \added_space_bottom vfill XML_RPC2 Tutorial \layout Abstract This tutorial introduces basic usage of XML_RPC2 as a client/server library in XML_RPC operations. XML_RPC2 is a pear package providing XML_RPC client and server services. XML-RPC is a simple remote procedure call protocol built using HTTP as transport and XML as encoding. \layout Abstract As a client library, XML_RPC2 is capable of creating a proxy class which exposes the methods exported by the server. As a server library, XML_RPC2 is capable of exposing methods from a class or object instance, seamlessly exporting local methods as remotely callable procedures. \layout Subsection Client usage \layout Subsubsection Basic Usage \layout Standard The most simple way to use the XML_RPC client is by letting XML_RPC2 select the backend for you, and just give the client factory method the data referring to the server: \layout Itemize The server URI. \layout Itemize The HTTP proxy URI (null if no proxy). \layout Itemize The method prefix \layout Code require_once('XML/RPC2/Client.php'); \layout Code $client = XML_RPC2_Client::create('http://rpc.example.com:80/', null, ''); \layout Standard The factory will produce a client proxy. This class exports whichever methods the server exports. These methods are called just like regular local methods: \layout Code print($client->hello('World')); \layout Standard for a server that exports the method hello. If the server has methods prefixed by a classname (example.hello), there are two solutions. Either call the method using brackets enclosing the otherwise php-invalid method name: \layout Code print($client->{example.hello}('World')); \layout Standard Or specify a method prefix when creating the client instance: \layout Code $client = XML_RPC2_Client::create('http://rpc.example.com:80/', null, 'example.'); \layout Code print($client->hello('World')); \layout Subsubsection Error handling \layout Standard XML_RPC2 uses exceptions to signal errors. The phpdoc reference contains a class hierarchy useful to get a grasp of possible errors. The most important characteristics of the XML_RPC2 exception tree are: \layout Itemize All XML_RPC2 exceptions are children of XML_RPC2_Exception. If you want to filter out exceptions from this package, catch XML_RPC2_Exceptio n \layout Itemize Network failure is signaled by an XML_RPC2_TransportException \layout Itemize Regular XML-RPC fault responses are signaled by an XML_RPC2_FaultException \layout Itemize All other types of XML_RPC2_Exception signal package misuse or bug-induced misbehaviour \layout Standard Standard usage: \layout Code require_once('XMLrequire_once('XML/RPC2/Client.php'); \layout Code try { \layout Code $client = XML_RPC2_Client::create('http://rpc.example.com:80/', null, ''); \layout Code print($client->hello('World')); \layout Code } catch (XML_RPC2_TransportException transportException) { \layout Code // Handle network-induced exception \layout Code } catch (XML_RPC2_FaultException fault) { \layout Code // Handle fault returned by remote server \layout Code } catch (XML_RPC2_Exception xmlRpcException) { \layout Code // Handle abnormal XML_RPC2 package exception \layout Code } catch (Exception e) { \layout Code // Handle someone else's fault exception \layout Code } \layout Standard It is good practice to at least expect XML_RPC2_TransportException as network failure can't ever be ruled out. \layout Subsection Server usage \layout Subsubsection Basic Usage \layout Standard To export an XML-RPC server using XML_RPC2, the first step is writing the methods to export. XML_RPC2 can export class methods (static methods) for a class, or all methods for an object instance. For this example, we'll export a class' static methods: \layout Code class EchoServer { \layout Code /** \layout Code * echoecho echoes the message received \layout Code * \layout Code * @param string Message \layout Code * @return string The echo \layout Code */ \layout Code \layout Code public static function echoecho($string) \layout Code { \layout Code return $string; \layout Code } \layout Code \layout Code /** \layout Code * Dummy method which won't be exported \layout Code * \layout Code * @xmlrpc.hidden \layout Code */ \layout Code public static function dummy() \layout Code { \layout Code return false; \layout Code } \layout Code \layout Code /** \layout Code * hello says hello \layout Code * \layout Code * @param string Name \layout Code * @return string Hello 'name' \layout Code */ \layout Code public function hello($name) \layout Code { \layout Code return "Hello $name"; \layout Code } \layout Code \layout Code } \layout Standard Note that the method is documented using phpDoc docblocks. The docblock is used to deduce the signature and method documentation, required by the XML-RPC spec. Non-documented methods are not exported. Methods tagged with the tag @xmlrpc.hidden are not exported either (the dummy method above won't be exported). \layout Standard After creating the class, we need to get an XML_RPC2 server to export its methods remotely: \layout Code require_once 'XML/RPC2/Server.php'; \layout Code $server = XML_RPC2_Server::create('EchoServer'); \layout Code $server->handleCall(); \layout Standard The XML_RPC2_Server automatically exports all of the EchoServer class public static methods (echoecho in this case). You may also export all of an instance's public methods (static or otherwise): \layout Code require_once 'XML/RPC2/Server.php'; \layout Code $server = XML_RPC2_Server::create(new EchoServer()); \layout Code $server->handleCall(); \the_end http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/client/faultFromPython.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/client/faultFromPython.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/client/faultFromPython.phpt --TEST-- PHP Backend XML-RPC client against python server returning fault response --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Client.php'; require_once 'XML/RPC2/Backend.php'; XML_RPC2_Backend::setBackend('php'); $client = XML_RPC2_Client::create('http://python.xmlrpc2test.sergiocarvalho.com:8765', '', null); try { $client->invalidMethod('World'); } catch (XML_RPC2_FaultException $e) { var_dump($e->getMessage()); } ?> --EXPECT-- string(60) "exceptions.Exception:method "invalidMethod" is not supported" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/client/okFromPython.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/client/okFromPython.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/client/okFromPython.phpt --TEST-- PHP Backend XML-RPC client against python server returning normal response --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Client.php'; require_once 'XML/RPC2/Backend.php'; XML_RPC2_Backend::setBackend('php'); $client = XML_RPC2_Client::create('http://python.xmlrpc2test.sergiocarvalho.com:8765', '', null); var_dump($client->echo('World')); ?> --EXPECT-- string(5) "World" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/client/protocolError.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/client/protocolError.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/client/protocolError.phpt --TEST-- PHP Backend XML-RPC client with transport error --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Client.php'; require_once 'XML/RPC2/Backend.php'; XML_RPC2_Backend::setBackend('php'); $client = XML_RPC2_Client::create('http://rpc.example.com:1000/', '', null); try { $client->invalidMethod('World'); } catch (XML_RPC2_CurlException $e) { var_dump($e->getMessage()); } ?> --EXPECTREGEX-- string\(.*\) \"Curl returned non-null errno.* http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/array.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/array.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/array.phpt --TEST-- Array XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Value.php'); var_dump(XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<?xml version="1.0"?><value><array><data><value><int>1</int></value><value><boolean>1</boolean></value><value><string>a</string></value></data></array></value>'))->getNativeValue()); ?> --EXPECT-- array(3) { [0]=> int(1) [1]=> bool(true) [2]=> string(1) "a" } http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/base64.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/base64.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/base64.phpt --TEST-- Base64 XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Value.php'); printf("Native value: %s\n", XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<?xml version="1.0"?><value><base64>VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2c=</base64></value>'))->getNativeValue()); ?> --EXPECT-- Native value: The quick brown fox jumped over the lazy dog http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/boolean.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/boolean.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/boolean.phpt --TEST-- Boolean XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Value.php'); printf("Native value: %s\n", XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<?xml version="1.0"?><value><boolean>0</boolean></value>'))->getNativeValue() ? 'true' : 'false'); printf("Native value: %s\n", XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<?xml version="1.0"?><value><boolean>1</boolean></value>'))->getNativeValue() ? 'true' : 'false'); ?> --EXPECT-- Native value: false Native value: true http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/datetime.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/datetime.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/datetime.phpt --TEST-- Datetime XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Value.php'); printf("Native value: %s\n", XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<?xml version="1.0"?><value><dateTime.iso8601>2005</dateTime.iso8601></value>'))->getNativeValue()); ?> --EXPECT-- Native value: 1104537600 http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/double.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/double.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/double.phpt --TEST-- Double XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Value.php'); printf("Native value: %s\n", XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<?xml version="1.0"?><value><double>1.25</double></value>'))->getNativeValue()); ?> --EXPECT-- Native value: 1.25 http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/faultResponse.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/faultResponse.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/faultResponse.phpt --TEST-- Response XML-RPC decoding (Php Backend) --FILE-- <?php try { set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Response.php'); var_dump(XML_RPC2_Backend_Php_Response::decode(simplexml_load_string(<<<XMLMARKER <?xml version="1.0"?> <methodResponse> <fault> <value><struct> <member><name>faultString</name><value><string>Failed to create homedir with: 0</string></value></member> <member><name>faultCode</name><value><i4>200</i4></value></member> </struct></value> </fault> </methodResponse> XMLMARKER ))); } catch (Exception $e) { var_dump($e->getMessage()); } ?> --EXPECT-- string(32) "Failed to create homedir with: 0" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/integer.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/integer.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/integer.phpt --TEST-- Integer XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Value.php'); printf("Native value: %s\n", XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<?xml version="1.0"?><value><int>13</int></value>'))->getNativeValue()); ?> --EXPECT-- Native value: 13 http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/integer2.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/integer2.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/integer2.phpt --TEST-- Integer XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Value.php'); printf("Native value: %s\n", XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<?xml version="1.0"?><value><i4>7</i4></value>'))->getNativeValue()); ?> --EXPECT-- Native value: 7 http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/request.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/request.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/request.phpt --TEST-- Request XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Request.php'); $request = XML_RPC2_Backend_Php_Request::createFromDecode(simplexml_load_string('<?xml version="1.0"?><methodCall><methodName>foo.bar</methodName><params><param><value><string>a string</string></value></param><param><value><int>125</int></value></param><param><value><double>125.2</double></value></param><param><value><dateTime.iso8601>19970716192030</dateTime.iso8601></value></param><param><value><boolean>1</boolean></value></param><param><value><boolean>0</boolean></value></param></params></methodCall>')); var_dump($request->getMethodName()); var_dump($request->getParameters()); ?> --EXPECT-- string(7) "foo.bar" array(6) { [0]=> string(8) "a string" [1]=> int(125) [2]=> float(125.2) [3]=> float(869011200) [4]=> bool(true) [5]=> bool(false) } http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/response.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/response.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/response.phpt --TEST-- Response XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Response.php'); var_dump(XML_RPC2_Backend_Php_Response::decode(simplexml_load_string('<?xml version="1.0"?><methodResponse><params><param><value><string>South Dakota</string></value></param></params></methodResponse>'))); ?> --EXPECT-- string(12) "South Dakota" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/string.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/string.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/string.phpt --TEST-- String XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Value.php'); printf("Native value: %s\n", XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<?xml version="1.0"?><value><string>The quick brown fox jumped over the lazy dog</string></value>'))->getNativeValue()); ?> --EXPECT-- Native value: The quick brown fox jumped over the lazy dog http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/struct.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/struct.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/decoding/struct.phpt --TEST-- Struct XML-RPC decoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once('XML/RPC2/Backend/Php/Value.php'); var_dump(XML_RPC2_Backend_Php_Value::createFromDecode(simplexml_load_string('<value><struct><member><name>a</name><value><int>1</int></value></member><member><name>b</name><value><boolean>1</boolean></value></member><member><name>c</name><value><string>a string</string></value></member></struct></value>'))->getNativeValue()); ?> --EXPECT-- array(3) { ["a"]=> int(1) ["b"]=> bool(true) ["c"]=> string(8) "a string" } http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/array.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/array.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/array.phpt --TEST-- Array XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Array.php'; $array = new XML_RPC2_Backend_Php_Value_Array(array(1, true, 'a string')); var_dump($array->encode()); ?> --EXPECT-- string(130) "<array><data><value><int>1</int></value><value><boolean>1</boolean></value><value><string>a string</string></value></data></array>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/base64.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/base64.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/base64.phpt --TEST-- Base64 XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Base64.php'; $string = new XML_RPC2_Backend_Php_Value_Base64('The quick brown fox jumped over the lazy dog'); var_dump($string->encode()); $string = new XML_RPC2_Backend_Php_Value_Base64('The <quick> brown fox jumped over the lazy dog'); var_dump($string->encode()); ?> --EXPECT-- string(77) "<base64>VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2c=</base64>" string(81) "<base64>VGhlIDxxdWljaz4gYnJvd24gZm94IGp1bXBlZCBvdmVyIHRoZSBsYXp5IGRvZw==</base64>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/boolean.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/boolean.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/boolean.phpt --TEST-- Boolean XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Boolean.php'; $bool = new XML_RPC2_Backend_Php_Value_Boolean(true); var_dump($bool->encode()); $bool = new XML_RPC2_Backend_Php_Value_Boolean(false); var_dump($bool->encode()); ?> --EXPECT-- string(20) "<boolean>1</boolean>" string(20) "<boolean>0</boolean>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime.phpt --TEST-- Datetime XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Datetime.php'; $time = new XML_RPC2_Backend_Php_Value_Datetime(853438830.45); var_dump($time->encode()); ?> --EXPECT-- string(49) "<dateTime.iso8601>853438830.45</dateTime.iso8601>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime1.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime1.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime1.phpt --TEST-- Datetime XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Datetime.php'; $time = new XML_RPC2_Backend_Php_Value_Datetime('1997-01-16T19:20:30.45+01:00'); var_dump($time->encode()); ?> --EXPECT-- string(49) "<dateTime.iso8601>853438830.45</dateTime.iso8601>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime2.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime2.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime2.phpt --TEST-- Datetime XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Datetime.php'; $time = new XML_RPC2_Backend_Php_Value_Datetime('1997-01-16T19:20:30.45Z'); var_dump($time->encode()); ?> --EXPECT-- string(49) "<dateTime.iso8601>853442430.45</dateTime.iso8601>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime3.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime3.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime3.phpt --TEST-- Datetime XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Datetime.php'; $time = new XML_RPC2_Backend_Php_Value_Datetime('2001'); var_dump($time->encode()); ?> --EXPECT-- string(46) "<dateTime.iso8601>978307200</dateTime.iso8601>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime4.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime4.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/datetime4.phpt --TEST-- Datetime XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Datetime.php'; $time = new XML_RPC2_Backend_Php_Value_Datetime('1997-01-16'); var_dump($time->encode()); ?> --EXPECT-- string(46) "<dateTime.iso8601>853372800</dateTime.iso8601>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/double.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/double.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/double.phpt --TEST-- Double XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Double.php'; $double = new XML_RPC2_Backend_Php_Value_Double(0); var_dump($double->encode()); $double = new XML_RPC2_Backend_Php_Value_Double(123.79); var_dump($double->encode()); ?> --EXPECT-- string(18) "<double>0</double>" string(23) "<double>123.79</double>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/integer.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/integer.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/integer.phpt --TEST-- Integer XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Integer.php'; $integer = new XML_RPC2_Backend_Php_Value_Integer(53); var_dump($integer->encode()); ?> --EXPECT-- string(13) "<int>53</int>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/request.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/request.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/request.phpt --TEST-- Request XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Request.php'; require_once 'XML/RPC2/Backend/Php/Value/Datetime.php'; $request = new XML_RPC2_Backend_Php_Request('foo.bar'); $request->addParameter('a string'); $request->addParameter(125); $request->addParameter(125.2); $request->addParameter(new XML_RPC2_Backend_Php_Value_Datetime('2005-01-03')); $request->addParameter(true); $request->addParameter(false); var_dump($request->encode()); ?> --EXPECT-- string(423) "<?xml version="1.0"?><methodCall><methodName>foo.bar</methodName><params><param><value><string>a string</string></value></param><param><value><int>125</int></value></param><param><value><double>125.2</double></value></param><param><value><dateTime.iso8601>1104710400</dateTime.iso8601></value></param><param><value><boolean>1</boolean></value></param><param><value><boolean>0</boolean></value></param></params></methodCall>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/response.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/response.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/response.phpt --TEST-- Request XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Response.php'; var_dump(XML_RPC2_Backend_Php_Response::encode(array(1, true, 'a string'))); ?> --EXPECT-- string(231) "<?xml version="1.0"?><methodResponse><params><param><value><array><data><value><int>1</int></value><value><boolean>1</boolean></value><value><string>a string</string></value></data></array></value></param></params></methodResponse>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/response2.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/response2.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/response2.phpt --TEST-- Request XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Response.php'; var_dump(XML_RPC2_Backend_Php_Response::encodeFault(2,'A fault string')); ?> --EXPECT-- string(254) "<?xml version="1.0"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>2</int></value></member><member><name>faultString</name><value><string>A fault string</string></value></member></struct></value></fault></methodResponse>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/string.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/string.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/string.phpt --TEST-- String XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/String.php'; $string = new XML_RPC2_Backend_Php_Value_String('The quick brown fox jumped over the lazy dog'); var_dump($string->encode()); $string = new XML_RPC2_Backend_Php_Value_String('The <quick> brown fox jumped over the lazy dog'); var_dump($string->encode()); ?> --EXPECT-- string(61) "<string>The quick brown fox jumped over the lazy dog</string>" string(69) "<string>The <quick> brown fox jumped over the lazy dog</string>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/struct.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/struct.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/encoding/struct.phpt --TEST-- Struct XML-RPC encoding (Php Backend) --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend/Php/Value/Struct.php'; $struct = new XML_RPC2_Backend_Php_Value_Struct(array('a' => 1, 'b' => true, 'c' => 'a string')); var_dump($struct->encode()); ?> --EXPECT-- string(212) "<struct><member><name>a</name><value><int>1</int></value></member><member><name>b</name><value><boolean>1</boolean></value></member><member><name>c</name><value><string>a string</string></value></member></struct>" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/server/invalidXMLRequest.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/server/invalidXMLRequest.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/server/invalidXMLRequest.phpt --TEST-- PHP Backend XML-RPC server with non-existant method response --FILE-- <?php class EchoServer { /** * echoecho echoes the message received * * @param string Message * @return string The echo */ public static function echoecho($string) { return $string; } } set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend.php'; require_once 'XML/RPC2/Server.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; XML_RPC2_Backend::setBackend('php'); $server = XML_RPC2_Server::create('EchoServer'); $GLOBALS['HTTP_RAW_POST_DATA'] = <<<EOS <?xml version="1.0"?> <methodCall> <methodName>echoecho</methodName> <params><param><value><string>World</string></value></param></prams> </methodCall> EOS ; ob_start(); $server->handleCall(); $response = ob_get_contents(); ob_end_clean(); try { XML_RPC2_Backend_Php_Response::decode(simplexml_load_string($response)); } catch (XML_RPC2_FaultException $e) { var_dump($e->getMessage()); } ?> --EXPECT-- string(27) "Unable to parse request XML" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/server/nonexistantMethod.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/server/nonexistantMethod.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/server/nonexistantMethod.phpt --TEST-- PHP Backend XML-RPC server with non-existant method response --FILE-- <?php class EchoServer { /** * echoecho echoes the message received * * @param string Message * @return string The echo */ public static function echoecho($string) { return $string; } } set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend.php'; require_once 'XML/RPC2/Server.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; XML_RPC2_Backend::setBackend('php'); $server = XML_RPC2_Server::create('EchoServer'); $GLOBALS['HTTP_RAW_POST_DATA'] = <<<EOS <?xml version="1.0"?> <methodCall> <methodName>example</methodName> <params><param><value><string>World</string></value></param></params> </methodCall> EOS ; ob_start(); $server->handleCall(); $response = ob_get_contents(); ob_end_clean(); try { XML_RPC2_Backend_Php_Response::decode(simplexml_load_string($response)); } catch (XML_RPC2_FaultException $e) { var_dump($e->getMessage()); } ?> --EXPECT-- string(97) "Unhandled XML_RPC2_UnknownMethodException exception:Method example is not exported by this server" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/phpBackend/server/normalRequest.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/phpBackend/server/normalRequest.phpt +++ pear/XML_RPC2/tests/XML_RPC2/phpBackend/server/normalRequest.phpt --TEST-- PHP Backend XML-RPC server with normal response --FILE-- <?php class EchoServer { /** * echoecho echoes the message received * * @param string Message * @return string The echo */ public static function echoecho($string) { return $string; } } set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend.php'; require_once 'XML/RPC2/Server.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; XML_RPC2_Backend::setBackend('php'); $server = XML_RPC2_Server::create('EchoServer'); $GLOBALS['HTTP_RAW_POST_DATA'] = <<<EOS <?xml version="1.0"?> <methodCall> <methodName>echoecho</methodName> <params><param><value><string>World</string></value></param></params> </methodCall> EOS ; ob_start(); $server->handleCall(); $response = ob_get_contents(); ob_end_clean(); var_dump(XML_RPC2_Backend_Php_Response::decode(simplexml_load_string($response))); ?> --EXPECT-- string(5) "World" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/faultFromPython.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/faultFromPython.phpt +++ pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/faultFromPython.phpt --TEST-- XMLRPCext Backend XML-RPC client against python server returning fault response --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Client.php'; require_once 'XML/RPC2/Backend.php'; XML_RPC2_Backend::setBackend('xmlrpcext'); $client = XML_RPC2_Client::create('http://python.xmlrpc2test.sergiocarvalho.com:8765', '', null); try { $client->invalidMethod('World'); } catch (XML_RPC2_FaultException $e) { var_dump($e->getMessage()); } ?> --EXPECT-- string(60) "exceptions.Exception:method "invalidMethod" is not supported" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/okFromPython.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/okFromPython.phpt +++ pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/okFromPython.phpt --TEST-- XMLRPCext Backend XML-RPC client against python server returning normal response --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Client.php'; require_once 'XML/RPC2/Backend.php'; XML_RPC2_Backend::setBackend('xmlrpcext'); $client = XML_RPC2_Client::create('http://python.xmlrpc2test.sergiocarvalho.com:8765', '', null); var_dump($client->echo('World')); ?> --EXPECT-- string(5) "World" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/protocolError.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/protocolError.phpt +++ pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/protocolError.phpt --TEST-- XMLRPCext Backend XML-RPC client with transport error --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Client.php'; require_once 'XML/RPC2/Backend.php'; XML_RPC2_Backend::setBackend('xmlrpcext'); $client = XML_RPC2_Client::create('http://rpc.example.com:1000/', '', null); try { $client->invalidMethod('World'); } catch (XML_RPC2_CurlException $e) { var_dump($e->getMessage()); } ?> --EXPECT-- string(70) "Curl returned non-null errno 6:Couldn't resolve host 'rpc.example.com'" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/valueCreateFromNative.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/valueCreateFromNative.phpt +++ pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/client/valueCreateFromNative.phpt --TEST-- XMLRPCext backend test setting explicit type for value --FILE-- <?php set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Value.php'; require_once 'XML/RPC2/Backend.php'; XML_RPC2_Backend::setBackend('xmlrpcext'); var_dump(XML_RPC2_Value::createFromNative('Hello World', 'base64')); ?> --EXPECT-- object(stdClass)#1 (2) { ["scalar"]=> string(11) "Hello World" ["xmlrpc_type"]=> string(6) "base64" } http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server/invalidXMLRequest.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server/invalidXMLRequest.phpt +++ pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server/invalidXMLRequest.phpt --TEST-- XMLRPCext Backend XML-RPC server with normal response --SKIPIF-- <?php // I can't silence expat errors anyhow. We're skipping this test // for xmlrpci print "skip"; --FILE-- <?php class EchoServer { /** * echoecho echoes the message received * * @param string Message * @return string The echo */ public static function echoecho($string) { return $string; } } set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend.php'; require_once 'XML/RPC2/Server.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; XML_RPC2_Backend::setBackend('XMLRPCext'); $server = XML_RPC2_Server::create('EchoServer'); $GLOBALS['HTTP_RAW_POST_DATA'] = <<<EOS <?xml version="1.0"?> <methodCall> <methodName>moo</methodName> <params><param><value><string>World</string></value></param></prams> </methodCall> EOS ; try { ob_start(); $server->handleCall(); $response = ob_get_contents(); ob_end_clean(); //print($response); //XML_RPC2_Backend_Php_Response::decode(simplexml_load_string($response)); } catch (XML_RPC2_FaultException $e) { var_dump($e->getMessage()); } ?> --EXPECT-- string(36) "server error. method not found. moo" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server/nonexistantMethod.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server/nonexistantMethod.phpt +++ pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server/nonexistantMethod.phpt --TEST-- XMLRPCext Backend XML-RPC server with normal response --FILE-- <?php class EchoServer { /** * echoecho echoes the message received * * @param string Message * @return string The echo */ public static function echoecho($string) { return $string; } } set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend.php'; require_once 'XML/RPC2/Server.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; XML_RPC2_Backend::setBackend('XMLRPCext'); $server = XML_RPC2_Server::create('EchoServer'); $GLOBALS['HTTP_RAW_POST_DATA'] = <<<EOS <?xml version="1.0"?> <methodCall> <methodName>moo</methodName> <params><param><value><string>World</string></value></param></params> </methodCall> EOS ; ob_start(); $server->handleCall(); $response = ob_get_contents(); ob_end_clean(); try { XML_RPC2_Backend_Php_Response::decode(simplexml_load_string($response)); } catch (XML_RPC2_FaultException $e) { var_dump($e->getMessage()); } ?> --EXPECT-- string(36) "server error. method not found. moo" http://cvs.php.net/co.php/pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server/normalRequest.phpt?r=1.1&p=1 Index: pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server/normalRequest.phpt +++ pear/XML_RPC2/tests/XML_RPC2/xmlrpcextBackend/server/normalRequest.phpt --TEST-- XMLRPCext Backend XML-RPC server with normal response --FILE-- <?php class EchoServer { /** * echoecho echoes the message received * * @param string Message * @return string The echo */ public static function echoecho($string) { return $string; } } set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path()); require_once 'XML/RPC2/Backend.php'; require_once 'XML/RPC2/Server.php'; require_once 'XML/RPC2/Backend/Php/Response.php'; XML_RPC2_Backend::setBackend('XMLRPCext'); $server = XML_RPC2_Server::create('EchoServer'); $GLOBALS['HTTP_RAW_POST_DATA'] = <<<EOS <?xml version="1.0"?> <methodCall> <methodName>echoecho</methodName> <params><param><value><string>World</string></value></param></params> </methodCall> EOS ; ob_start(); $server->handleCall(); $response = ob_get_contents(); ob_end_clean(); var_dump(XML_RPC2_Backend_Php_Response::decode(simplexml_load_string($response))); ?> --EXPECT-- string(5) "World" http://cvs.php.net/co.php/pear/XML_RPC2/util/filelist.sh?r=1.1&p=1 Index: pear/XML_RPC2/util/filelist.sh +++ pear/XML_RPC2/util/filelist.sh #!/bin/bash listdir () { if [ "$i" = '.' ]; then return; fi if [ "$i" = '..' ]; then return; fi if [ -d $1 ] then echo "<dir name=\"$(basename $1)\" role=\"$2\">" cd $1 for i in `ls -1` do listdir $i $2 done cd .. echo "</dir>" else echo "<file name=\"$(basename $1)\" />" fi } listdir XML php listdir tests/XML_RPC2 test http://cvs.php.net/co.php/pear/XML_RPC2/util/indent.xsl?r=1.1&p=1 Index: pear/XML_RPC2/util/indent.xsl +++ pear/XML_RPC2/util/indent.xsl <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="/"> <xsl:copy-of select="."/> </xsl:template> </xsl:stylesheet>