CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.

This commit is contained in:
Paul Baranowski 2011-04-14 18:55:04 -04:00
parent 514777e8d2
commit b11cbd8159
4546 changed files with 138 additions and 51 deletions

View file

@ -0,0 +1,386 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Client.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* For handling the HTTP connection to the XML-RPC service
* @see Zend_Http_Client
*/
require_once 'Zend/Http/Client.php';
/**
* Enables object chaining for calling namespaced XML-RPC methods.
* @see Zend_XmlRpc_Client_ServerProxy
*/
require_once 'Zend/XmlRpc/Client/ServerProxy.php';
/**
* Introspects remote servers using the XML-RPC de facto system.* methods
* @see Zend_XmlRpc_Client_ServerIntrospection
*/
require_once 'Zend/XmlRpc/Client/ServerIntrospection.php';
/**
* Represent a native XML-RPC value, used both in sending parameters
* to methods and as the parameters retrieve from method calls
* @see Zend_XmlRpc_Value
*/
require_once 'Zend/XmlRpc/Value.php';
/**
* XML-RPC Request
* @see Zend_XmlRpc_Request
*/
require_once 'Zend/XmlRpc/Request.php';
/**
* XML-RPC Response
* @see Zend_XmlRpc_Response
*/
require_once 'Zend/XmlRpc/Response.php';
/**
* XML-RPC Fault
* @see Zend_XmlRpc_Fault
*/
require_once 'Zend/XmlRpc/Fault.php';
/**
* An XML-RPC client implementation
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Client
{
/**
* Full address of the XML-RPC service
* @var string
* @example http://time.xmlrpc.com/RPC2
*/
protected $_serverAddress;
/**
* HTTP Client to use for requests
* @var Zend_Http_Client
*/
protected $_httpClient = null;
/**
* Introspection object
* @var Zend_Http_Client_Introspector
*/
protected $_introspector = null;
/**
* Request of the last method call
* @var Zend_XmlRpc_Request
*/
protected $_lastRequest = null;
/**
* Response received from the last method call
* @var Zend_XmlRpc_Response
*/
protected $_lastResponse = null;
/**
* Proxy object for more convenient method calls
* @var array of Zend_XmlRpc_Client_ServerProxy
*/
protected $_proxyCache = array();
/**
* Flag for skipping system lookup
* @var bool
*/
protected $_skipSystemLookup = false;
/**
* Create a new XML-RPC client to a remote server
*
* @param string $server Full address of the XML-RPC service
* (e.g. http://time.xmlrpc.com/RPC2)
* @param Zend_Http_Client $httpClient HTTP Client to use for requests
* @return void
*/
public function __construct($server, Zend_Http_Client $httpClient = null)
{
if ($httpClient === null) {
$this->_httpClient = new Zend_Http_Client();
} else {
$this->_httpClient = $httpClient;
}
$this->_introspector = new Zend_XmlRpc_Client_ServerIntrospection($this);
$this->_serverAddress = $server;
}
/**
* Sets the HTTP client object to use for connecting the XML-RPC server.
*
* @param Zend_Http_Client $httpClient
* @return Zend_Http_Client
*/
public function setHttpClient(Zend_Http_Client $httpClient)
{
return $this->_httpClient = $httpClient;
}
/**
* Gets the HTTP client object.
*
* @return Zend_Http_Client
*/
public function getHttpClient()
{
return $this->_httpClient;
}
/**
* Sets the object used to introspect remote servers
*
* @param Zend_XmlRpc_Client_ServerIntrospection
* @return Zend_XmlRpc_Client_ServerIntrospection
*/
public function setIntrospector(Zend_XmlRpc_Client_ServerIntrospection $introspector)
{
return $this->_introspector = $introspector;
}
/**
* Gets the introspection object.
*
* @return Zend_XmlRpc_Client_ServerIntrospection
*/
public function getIntrospector()
{
return $this->_introspector;
}
/**
* The request of the last method call
*
* @return Zend_XmlRpc_Request
*/
public function getLastRequest()
{
return $this->_lastRequest;
}
/**
* The response received from the last method call
*
* @return Zend_XmlRpc_Response
*/
public function getLastResponse()
{
return $this->_lastResponse;
}
/**
* Returns a proxy object for more convenient method calls
*
* @param $namespace Namespace to proxy or empty string for none
* @return Zend_XmlRpc_Client_ServerProxy
*/
public function getProxy($namespace = '')
{
if (empty($this->_proxyCache[$namespace])) {
$proxy = new Zend_XmlRpc_Client_ServerProxy($this, $namespace);
$this->_proxyCache[$namespace] = $proxy;
}
return $this->_proxyCache[$namespace];
}
/**
* Set skip system lookup flag
*
* @param bool $flag
* @return Zend_XmlRpc_Client
*/
public function setSkipSystemLookup($flag = true)
{
$this->_skipSystemLookup = (bool) $flag;
return $this;
}
/**
* Skip system lookup when determining if parameter should be array or struct?
*
* @return bool
*/
public function skipSystemLookup()
{
return $this->_skipSystemLookup;
}
/**
* Perform an XML-RPC request and return a response.
*
* @param Zend_XmlRpc_Request $request
* @param null|Zend_XmlRpc_Response $response
* @return void
* @throws Zend_XmlRpc_Client_HttpException
*/
public function doRequest($request, $response = null)
{
$this->_lastRequest = $request;
iconv_set_encoding('input_encoding', 'UTF-8');
iconv_set_encoding('output_encoding', 'UTF-8');
iconv_set_encoding('internal_encoding', 'UTF-8');
$http = $this->getHttpClient();
if($http->getUri() === null) {
$http->setUri($this->_serverAddress);
}
$http->setHeaders(array(
'Content-Type: text/xml; charset=utf-8',
'Accept: text/xml',
));
if ($http->getHeader('user-agent') === null) {
$http->setHeaders(array('User-Agent: Zend_XmlRpc_Client'));
}
$xml = $this->_lastRequest->__toString();
$http->setRawData($xml);
$httpResponse = $http->request(Zend_Http_Client::POST);
if (! $httpResponse->isSuccessful()) {
/**
* Exception thrown when an HTTP error occurs
* @see Zend_XmlRpc_Client_HttpException
*/
require_once 'Zend/XmlRpc/Client/HttpException.php';
throw new Zend_XmlRpc_Client_HttpException(
$httpResponse->getMessage(),
$httpResponse->getStatus());
}
if ($response === null) {
$response = new Zend_XmlRpc_Response();
}
$this->_lastResponse = $response;
$this->_lastResponse->loadXml($httpResponse->getBody());
}
/**
* Send an XML-RPC request to the service (for a specific method)
*
* @param string $method Name of the method we want to call
* @param array $params Array of parameters for the method
* @return mixed
* @throws Zend_XmlRpc_Client_FaultException
*/
public function call($method, $params=array())
{
if (!$this->skipSystemLookup() && ('system.' != substr($method, 0, 7))) {
// Ensure empty array/struct params are cast correctly
// If system.* methods are not available, bypass. (ZF-2978)
$success = true;
try {
$signatures = $this->getIntrospector()->getMethodSignature($method);
} catch (Zend_XmlRpc_Exception $e) {
$success = false;
}
if ($success) {
$validTypes = array(
Zend_XmlRpc_Value::XMLRPC_TYPE_ARRAY,
Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64,
Zend_XmlRpc_Value::XMLRPC_TYPE_BOOLEAN,
Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME,
Zend_XmlRpc_Value::XMLRPC_TYPE_DOUBLE,
Zend_XmlRpc_Value::XMLRPC_TYPE_I4,
Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER,
Zend_XmlRpc_Value::XMLRPC_TYPE_NIL,
Zend_XmlRpc_Value::XMLRPC_TYPE_STRING,
Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT,
);
if (!is_array($params)) {
$params = array($params);
}
foreach ($params as $key => $param) {
if ($param instanceof Zend_XmlRpc_Value) {
continue;
}
$type = Zend_XmlRpc_Value::AUTO_DETECT_TYPE;
foreach ($signatures as $signature) {
if (!is_array($signature)) {
continue;
}
if (isset($signature['parameters'][$key])) {
$type = $signature['parameters'][$key];
$type = in_array($type, $validTypes) ? $type : Zend_XmlRpc_Value::AUTO_DETECT_TYPE;
}
}
$params[$key] = Zend_XmlRpc_Value::getXmlRpcValue($param, $type);
}
}
}
$request = $this->_createRequest($method, $params);
$this->doRequest($request);
if ($this->_lastResponse->isFault()) {
$fault = $this->_lastResponse->getFault();
/**
* Exception thrown when an XML-RPC fault is returned
* @see Zend_XmlRpc_Client_FaultException
*/
require_once 'Zend/XmlRpc/Client/FaultException.php';
throw new Zend_XmlRpc_Client_FaultException($fault->getMessage(),
$fault->getCode());
}
return $this->_lastResponse->getReturnValue();
}
/**
* Create request object
*
* @return Zend_XmlRpc_Request
*/
protected function _createRequest($method, $params)
{
return new Zend_XmlRpc_Request($method, $params);
}
}

View file

@ -0,0 +1,40 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Zend_XmlRpc_Exception
*/
require_once 'Zend/XmlRpc/Exception.php';
/**
* Base class for all Zend_XmlRpc_Client_* exceptions
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Client_Exception extends Zend_XmlRpc_Exception
{}

View file

@ -0,0 +1,38 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: FaultException.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_XmlRpc_Client_Exception */
require_once 'Zend/XmlRpc/Client/Exception.php';
/**
* Thrown by Zend_XmlRpc_Client when an XML-RPC fault response is returned.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Client_FaultException extends Zend_XmlRpc_Client_Exception
{}

View file

@ -0,0 +1,41 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: HttpException.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Zend_XmlRpc_Exception
*/
require_once 'Zend/XmlRpc/Client/Exception.php';
/**
* Thrown by Zend_XmlRpc_Client when an HTTP error occurs during an
* XML-RPC method call.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Client_HttpException extends Zend_XmlRpc_Client_Exception
{}

View file

@ -0,0 +1,40 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: IntrospectException.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Zend_XmlRpc_Client_Exception
*/
require_once 'Zend/XmlRpc/Client/Exception.php';
/**
* Thrown by Zend_XmlRpc_Client_Introspection when any error occurs.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Client_IntrospectException extends Zend_XmlRpc_Client_Exception
{}

View file

@ -0,0 +1,166 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: ServerIntrospection.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Wraps the XML-RPC system.* introspection methods
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Client_ServerIntrospection
{
/**
* @var Zend_XmlRpc_Client_ServerProxy
*/
private $_system = null;
/**
* @param Zend_XmlRpc_Client $client
*/
public function __construct(Zend_XmlRpc_Client $client)
{
$this->_system = $client->getProxy('system');
}
/**
* Returns the signature for each method on the server,
* autodetecting whether system.multicall() is supported and
* using it if so.
*
* @return array
*/
public function getSignatureForEachMethod()
{
$methods = $this->listMethods();
require_once 'Zend/XmlRpc/Client/FaultException.php';
try {
$signatures = $this->getSignatureForEachMethodByMulticall($methods);
} catch (Zend_XmlRpc_Client_FaultException $e) {
// degrade to looping
}
if (empty($signatures)) {
$signatures = $this->getSignatureForEachMethodByLooping($methods);
}
return $signatures;
}
/**
* Attempt to get the method signatures in one request via system.multicall().
* This is a boxcar feature of XML-RPC and is found on fewer servers. However,
* can significantly improve performance if present.
*
* @param array $methods
* @return array array(array(return, param, param, param...))
*/
public function getSignatureForEachMethodByMulticall($methods = null)
{
if ($methods === null) {
$methods = $this->listMethods();
}
$multicallParams = array();
foreach ($methods as $method) {
$multicallParams[] = array('methodName' => 'system.methodSignature',
'params' => array($method));
}
$serverSignatures = $this->_system->multicall($multicallParams);
if (! is_array($serverSignatures)) {
$type = gettype($serverSignatures);
$error = "Multicall return is malformed. Expected array, got $type";
require_once 'Zend/XmlRpc/Client/IntrospectException.php';
throw new Zend_XmlRpc_Client_IntrospectException($error);
}
if (count($serverSignatures) != count($methods)) {
$error = 'Bad number of signatures received from multicall';
require_once 'Zend/XmlRpc/Client/IntrospectException.php';
throw new Zend_XmlRpc_Client_IntrospectException($error);
}
// Create a new signatures array with the methods name as keys and the signature as value
$signatures = array();
foreach ($serverSignatures as $i => $signature) {
$signatures[$methods[$i]] = $signature;
}
return $signatures;
}
/**
* Get the method signatures for every method by
* successively calling system.methodSignature
*
* @param array $methods
* @return array
*/
public function getSignatureForEachMethodByLooping($methods = null)
{
if ($methods === null) {
$methods = $this->listMethods();
}
$signatures = array();
foreach ($methods as $method) {
$signatures[$method] = $this->getMethodSignature($method);
}
return $signatures;
}
/**
* Call system.methodSignature() for the given method
*
* @param array $method
* @return array array(array(return, param, param, param...))
*/
public function getMethodSignature($method)
{
$signature = $this->_system->methodSignature($method);
if (!is_array($signature)) {
$error = 'Invalid signature for method "' . $method . '"';
require_once 'Zend/XmlRpc/Client/IntrospectException.php';
throw new Zend_XmlRpc_Client_IntrospectException($error);
}
return $signature;
}
/**
* Call system.listMethods()
*
* @param array $method
* @return array array(method, method, method...)
*/
public function listMethods()
{
return $this->_system->listMethods();
}
}

View file

@ -0,0 +1,95 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: ServerProxy.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* The namespace decorator enables object chaining to permit
* calling XML-RPC namespaced functions like "foo.bar.baz()"
* as "$remote->foo->bar->baz()".
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Client
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Client_ServerProxy
{
/**
* @var Zend_XmlRpc_Client
*/
private $_client = null;
/**
* @var string
*/
private $_namespace = '';
/**
* @var array of Zend_XmlRpc_Client_ServerProxy
*/
private $_cache = array();
/**
* Class constructor
*
* @param string $namespace
* @param Zend_XmlRpc_Client $client
*/
public function __construct($client, $namespace = '')
{
$this->_namespace = $namespace;
$this->_client = $client;
}
/**
* Get the next successive namespace
*
* @param string $name
* @return Zend_XmlRpc_Client_ServerProxy
*/
public function __get($namespace)
{
$namespace = ltrim("$this->_namespace.$namespace", '.');
if (!isset($this->_cache[$namespace])) {
$this->_cache[$namespace] = new $this($this->_client, $namespace);
}
return $this->_cache[$namespace];
}
/**
* Call a method in this namespace.
*
* @param string $methodN
* @param array $args
* @return mixed
*/
public function __call($method, $args)
{
$method = ltrim("$this->_namespace.$method", '.');
return $this->_client->call($method, $args);
}
}

View file

@ -0,0 +1,37 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Exception extends Zend_Exception
{}

View file

@ -0,0 +1,307 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @package Zend_XmlRpc
* @subpackage Server
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Fault.php 20208 2010-01-11 22:37:37Z lars $
*/
/**
* Zend_XmlRpc_Value
*/
require_once 'Zend/XmlRpc/Value.php';
/**
* XMLRPC Faults
*
* Container for XMLRPC faults, containing both a code and a message;
* additionally, has methods for determining if an XML response is an XMLRPC
* fault, as well as generating the XML for an XMLRPC fault response.
*
* To allow method chaining, you may only use the {@link getInstance()} factory
* to instantiate a Zend_XmlRpc_Server_Fault.
*
* @category Zend
* @package Zend_XmlRpc
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Fault
{
/**
* Fault code
* @var int
*/
protected $_code;
/**
* Fault character encoding
* @var string
*/
protected $_encoding = 'UTF-8';
/**
* Fault message
* @var string
*/
protected $_message;
/**
* Internal fault codes => messages
* @var array
*/
protected $_internal = array(
404 => 'Unknown Error',
// 610 - 619 reflection errors
610 => 'Invalid method class',
611 => 'Unable to attach function or callback; not callable',
612 => 'Unable to load array; not an array',
613 => 'One or more method records are corrupt or otherwise unusable',
// 620 - 629 dispatch errors
620 => 'Method does not exist',
621 => 'Error instantiating class to invoke method',
622 => 'Method missing implementation',
623 => 'Calling parameters do not match signature',
// 630 - 639 request errors
630 => 'Unable to read request',
631 => 'Failed to parse request',
632 => 'Invalid request, no method passed; request must contain a \'methodName\' tag',
633 => 'Param must contain a value',
634 => 'Invalid method name',
635 => 'Invalid XML provided to request',
636 => 'Error creating xmlrpc value',
// 640 - 649 system.* errors
640 => 'Method does not exist',
// 650 - 659 response errors
650 => 'Invalid XML provided for response',
651 => 'Failed to parse response',
652 => 'Invalid response',
653 => 'Invalid XMLRPC value in response',
);
/**
* Constructor
*
* @return Zend_XmlRpc_Fault
*/
public function __construct($code = 404, $message = '')
{
$this->setCode($code);
$code = $this->getCode();
if (empty($message) && isset($this->_internal[$code])) {
$message = $this->_internal[$code];
} elseif (empty($message)) {
$message = 'Unknown error';
}
$this->setMessage($message);
}
/**
* Set the fault code
*
* @param int $code
* @return Zend_XmlRpc_Fault
*/
public function setCode($code)
{
$this->_code = (int) $code;
return $this;
}
/**
* Return fault code
*
* @return int
*/
public function getCode()
{
return $this->_code;
}
/**
* Retrieve fault message
*
* @param string
* @return Zend_XmlRpc_Fault
*/
public function setMessage($message)
{
$this->_message = (string) $message;
return $this;
}
/**
* Retrieve fault message
*
* @return string
*/
public function getMessage()
{
return $this->_message;
}
/**
* Set encoding to use in fault response
*
* @param string $encoding
* @return Zend_XmlRpc_Fault
*/
public function setEncoding($encoding)
{
$this->_encoding = $encoding;
Zend_XmlRpc_Value::setEncoding($encoding);
return $this;
}
/**
* Retrieve current fault encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* Load an XMLRPC fault from XML
*
* @param string $fault
* @return boolean Returns true if successfully loaded fault response, false
* if response was not a fault response
* @throws Zend_XmlRpc_Exception if no or faulty XML provided, or if fault
* response does not contain either code or message
*/
public function loadXml($fault)
{
if (!is_string($fault)) {
require_once 'Zend/XmlRpc/Exception.php';
throw new Zend_XmlRpc_Exception('Invalid XML provided to fault');
}
try {
$xml = @new SimpleXMLElement($fault);
} catch (Exception $e) {
// Not valid XML
require_once 'Zend/XmlRpc/Exception.php';
throw new Zend_XmlRpc_Exception('Failed to parse XML fault: ' . $e->getMessage(), 500, $e);
}
// Check for fault
if (!$xml->fault) {
// Not a fault
return false;
}
if (!$xml->fault->value->struct) {
// not a proper fault
require_once 'Zend/XmlRpc/Exception.php';
throw new Zend_XmlRpc_Exception('Invalid fault structure', 500);
}
$structXml = $xml->fault->value->asXML();
$struct = Zend_XmlRpc_Value::getXmlRpcValue($structXml, Zend_XmlRpc_Value::XML_STRING);
$struct = $struct->getValue();
if (isset($struct['faultCode'])) {
$code = $struct['faultCode'];
}
if (isset($struct['faultString'])) {
$message = $struct['faultString'];
}
if (empty($code) && empty($message)) {
require_once 'Zend/XmlRpc/Exception.php';
throw new Zend_XmlRpc_Exception('Fault code and string required');
}
if (empty($code)) {
$code = '404';
}
if (empty($message)) {
if (isset($this->_internal[$code])) {
$message = $this->_internal[$code];
} else {
$message = 'Unknown Error';
}
}
$this->setCode($code);
$this->setMessage($message);
return true;
}
/**
* Determine if an XML response is an XMLRPC fault
*
* @param string $xml
* @return boolean
*/
public static function isFault($xml)
{
$fault = new self();
require_once 'Zend/XmlRpc/Exception.php';
try {
$isFault = $fault->loadXml($xml);
} catch (Zend_XmlRpc_Exception $e) {
$isFault = false;
}
return $isFault;
}
/**
* Serialize fault to XML
*
* @return string
*/
public function saveXml()
{
// Create fault value
$faultStruct = array(
'faultCode' => $this->getCode(),
'faultString' => $this->getMessage()
);
$value = Zend_XmlRpc_Value::getXmlRpcValue($faultStruct);
$generator = Zend_XmlRpc_Value::getGenerator();
$generator->openElement('methodResponse')
->openElement('fault');
$value->generateXml();
$generator->closeElement('fault')
->closeElement('methodResponse');
return $generator->flush();
}
/**
* Return XML fault response
*
* @return string
*/
public function __toString()
{
return $this->saveXML();
}
}

View file

@ -0,0 +1,101 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Generator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Client.php 17752 2009-08-22 15:49:54Z lars $
*/
/**
* @var Zend_XmlRpc_Generator_GeneratorAbstract
*/
require_once 'Zend/XmlRpc/Generator/GeneratorAbstract.php';
/**
* DOMDocument based implementation of a XML/RPC generator
*/
class Zend_XmlRpc_Generator_DomDocument extends Zend_XmlRpc_Generator_GeneratorAbstract
{
/**
* @var DOMDocument
*/
protected $_dom;
/**
* @var DOMNode
*/
protected $_currentElement;
/**
* Start XML element
*
* @param string $name
* @return void
*/
protected function _openElement($name)
{
$newElement = $this->_dom->createElement($name);
$this->_currentElement = $this->_currentElement->appendChild($newElement);
}
/**
* Write XML text data into the currently opened XML element
*
* @param string $text
*/
protected function _writeTextData($text)
{
$this->_currentElement->appendChild($this->_dom->createTextNode($text));
}
/**
* Close an previously opened XML element
*
* Resets $_currentElement to the next parent node in the hierarchy
*
* @param string $name
* @return void
*/
protected function _closeElement($name)
{
if (isset($this->_currentElement->parentNode)) {
$this->_currentElement = $this->_currentElement->parentNode;
}
}
/**
* Save XML as a string
*
* @return string
*/
public function saveXml()
{
return $this->_dom->saveXml();
}
/**
* Initializes internal objects
*
* @return void
*/
protected function _init()
{
$this->_dom = new DOMDocument('1.0', $this->_encoding);
$this->_currentElement = $this->_dom;
}
}

View file

@ -0,0 +1,150 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Generator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Client.php 17752 2009-08-22 15:49:54Z lars $
*/
/**
* Abstract XML generator adapter
*/
abstract class Zend_XmlRpc_Generator_GeneratorAbstract
{
/**
* XML encoding string
*
* @var string
*/
protected $_encoding;
/**
* Construct new instance of the generator
*
* @param string $encoding XML encoding, default UTF-8
*/
public function __construct($encoding = 'UTF-8')
{
$this->_encoding = $encoding;
$this->_init();
}
/**
* Start XML element
*
* Method opens a new XML element with an element name and an optional value
*
* @param string $name XML tag name
* @param string $value Optional value of the XML tag
* @return Zend_XmlRpc_Generator_Abstract Fluent interface
*/
public function openElement($name, $value = null)
{
$this->_openElement($name);
if ($value !== null) {
$this->_writeTextData($value);
}
return $this;
}
/**
* End of an XML element
*
* Method marks the end of an XML element
*
* @param string $name XML tag name
* @return Zend_XmlRpc_Generator_Abstract Fluent interface
*/
public function closeElement($name)
{
$this->_closeElement($name);
return $this;
}
/**
* Return XML as a string
*
* @return string
*/
abstract public function saveXml();
/**
* Return encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* Returns the XML as a string and flushes all internal buffers
*
* @return string
*/
public function flush()
{
$xml = $this->saveXml();
$this->_init();
return $xml;
}
/**
* Returns XML without document declaration
*
* @return string
*/
public function __toString()
{
return $this->stripDeclaration($this->saveXml());
}
/**
* Removes XML declaration from a string
*
* @param string $xml
* @return string
*/
public function stripDeclaration($xml)
{
return preg_replace('/<\?xml version="1.0"( encoding="[^\"]*")?\?>\n/u', '', $xml);
}
/**
* Start XML element
*
* @param string $name XML element name
*/
abstract protected function _openElement($name);
/**
* Write XML text data into the currently opened XML element
*
* @param string $text
*/
abstract protected function _writeTextData($text);
/**
* End XML element
*
* @param string $name
*/
abstract protected function _closeElement($name);
}

View file

@ -0,0 +1,92 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Generator
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Client.php 17752 2009-08-22 15:49:54Z lars $
*/
/**
* @var Zend_XmlRpc_Generator_GeneratorAbstract
*/
require_once 'Zend/XmlRpc/Generator/GeneratorAbstract.php';
/**
* XML generator adapter based on XMLWriter
*/
class Zend_XmlRpc_Generator_XmlWriter extends Zend_XmlRpc_Generator_GeneratorAbstract
{
/**
* XMLWriter instance
*
* @var XMLWriter
*/
protected $_xmlWriter;
/**
* Initialized XMLWriter instance
*
* @return void
*/
protected function _init()
{
$this->_xmlWriter = new XMLWriter();
$this->_xmlWriter->openMemory();
$this->_xmlWriter->startDocument('1.0', $this->_encoding);
}
/**
* Open a new XML element
*
* @param string $name XML element name
* @return void
*/
protected function _openElement($name)
{
$this->_xmlWriter->startElement($name);
}
/**
* Write XML text data into the currently opened XML element
*
* @param string $text XML text data
* @return void
*/
protected function _writeTextData($text)
{
$this->_xmlWriter->text($text);
}
/**
* Close an previously opened XML element
*
* @param string $name
* @return void
*/
protected function _closeElement($name)
{
$this->_xmlWriter->endElement();
return $this;
}
public function saveXml()
{
return $this->_xmlWriter->flush(false);
}
}

View file

@ -0,0 +1,439 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Controller
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_XmlRpc_Value
*/
require_once 'Zend/XmlRpc/Value.php';
/**
* Zend_XmlRpc_Fault
*/
require_once 'Zend/XmlRpc/Fault.php';
/**
* XmlRpc Request object
*
* Encapsulates an XmlRpc request, holding the method call and all parameters.
* Provides accessors for these, as well as the ability to load from XML and to
* create the XML request string.
*
* Additionally, if errors occur setting the method or parsing XML, a fault is
* generated and stored in {@link $_fault}; developers may check for it using
* {@link isFault()} and {@link getFault()}.
*
* @category Zend
* @package Zend_XmlRpc
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Request.php 20208 2010-01-11 22:37:37Z lars $
*/
class Zend_XmlRpc_Request
{
/**
* Request character encoding
* @var string
*/
protected $_encoding = 'UTF-8';
/**
* Method to call
* @var string
*/
protected $_method;
/**
* XML request
* @var string
*/
protected $_xml;
/**
* Method parameters
* @var array
*/
protected $_params = array();
/**
* Fault object, if any
* @var Zend_XmlRpc_Fault
*/
protected $_fault = null;
/**
* XML-RPC type for each param
* @var array
*/
protected $_types = array();
/**
* XML-RPC request params
* @var array
*/
protected $_xmlRpcParams = array();
/**
* Create a new XML-RPC request
*
* @param string $method (optional)
* @param array $params (optional)
*/
public function __construct($method = null, $params = null)
{
if ($method !== null) {
$this->setMethod($method);
}
if ($params !== null) {
$this->setParams($params);
}
}
/**
* Set encoding to use in request
*
* @param string $encoding
* @return Zend_XmlRpc_Request
*/
public function setEncoding($encoding)
{
$this->_encoding = $encoding;
Zend_XmlRpc_Value::setEncoding($encoding);
return $this;
}
/**
* Retrieve current request encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* Set method to call
*
* @param string $method
* @return boolean Returns true on success, false if method name is invalid
*/
public function setMethod($method)
{
if (!is_string($method) || !preg_match('/^[a-z0-9_.:\/]+$/i', $method)) {
$this->_fault = new Zend_XmlRpc_Fault(634, 'Invalid method name ("' . $method . '")');
$this->_fault->setEncoding($this->getEncoding());
return false;
}
$this->_method = $method;
return true;
}
/**
* Retrieve call method
*
* @return string
*/
public function getMethod()
{
return $this->_method;
}
/**
* Add a parameter to the parameter stack
*
* Adds a parameter to the parameter stack, associating it with the type
* $type if provided
*
* @param mixed $value
* @param string $type Optional; type hinting
* @return void
*/
public function addParam($value, $type = null)
{
$this->_params[] = $value;
if (null === $type) {
// Detect type if not provided explicitly
if ($value instanceof Zend_XmlRpc_Value) {
$type = $value->getType();
} else {
$xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($value);
$type = $xmlRpcValue->getType();
}
}
$this->_types[] = $type;
$this->_xmlRpcParams[] = array('value' => $value, 'type' => $type);
}
/**
* Set the parameters array
*
* If called with a single, array value, that array is used to set the
* parameters stack. If called with multiple values or a single non-array
* value, the arguments are used to set the parameters stack.
*
* Best is to call with array of the format, in order to allow type hinting
* when creating the XMLRPC values for each parameter:
* <code>
* $array = array(
* array(
* 'value' => $value,
* 'type' => $type
* )[, ... ]
* );
* </code>
*
* @access public
* @return void
*/
public function setParams()
{
$argc = func_num_args();
$argv = func_get_args();
if (0 == $argc) {
return;
}
if ((1 == $argc) && is_array($argv[0])) {
$params = array();
$types = array();
$wellFormed = true;
foreach ($argv[0] as $arg) {
if (!is_array($arg) || !isset($arg['value'])) {
$wellFormed = false;
break;
}
$params[] = $arg['value'];
if (!isset($arg['type'])) {
$xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($arg['value']);
$arg['type'] = $xmlRpcValue->getType();
}
$types[] = $arg['type'];
}
if ($wellFormed) {
$this->_xmlRpcParams = $argv[0];
$this->_params = $params;
$this->_types = $types;
} else {
$this->_params = $argv[0];
$this->_types = array();
$xmlRpcParams = array();
foreach ($argv[0] as $arg) {
if ($arg instanceof Zend_XmlRpc_Value) {
$type = $arg->getType();
} else {
$xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($arg);
$type = $xmlRpcValue->getType();
}
$xmlRpcParams[] = array('value' => $arg, 'type' => $type);
$this->_types[] = $type;
}
$this->_xmlRpcParams = $xmlRpcParams;
}
return;
}
$this->_params = $argv;
$this->_types = array();
$xmlRpcParams = array();
foreach ($argv as $arg) {
if ($arg instanceof Zend_XmlRpc_Value) {
$type = $arg->getType();
} else {
$xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($arg);
$type = $xmlRpcValue->getType();
}
$xmlRpcParams[] = array('value' => $arg, 'type' => $type);
$this->_types[] = $type;
}
$this->_xmlRpcParams = $xmlRpcParams;
}
/**
* Retrieve the array of parameters
*
* @return array
*/
public function getParams()
{
return $this->_params;
}
/**
* Return parameter types
*
* @return array
*/
public function getTypes()
{
return $this->_types;
}
/**
* Load XML and parse into request components
*
* @param string $request
* @return boolean True on success, false if an error occurred.
*/
public function loadXml($request)
{
if (!is_string($request)) {
$this->_fault = new Zend_XmlRpc_Fault(635);
$this->_fault->setEncoding($this->getEncoding());
return false;
}
try {
$xml = new SimpleXMLElement($request);
} catch (Exception $e) {
// Not valid XML
$this->_fault = new Zend_XmlRpc_Fault(631);
$this->_fault->setEncoding($this->getEncoding());
return false;
}
// Check for method name
if (empty($xml->methodName)) {
// Missing method name
$this->_fault = new Zend_XmlRpc_Fault(632);
$this->_fault->setEncoding($this->getEncoding());
return false;
}
$this->_method = (string) $xml->methodName;
// Check for parameters
if (!empty($xml->params)) {
$types = array();
$argv = array();
foreach ($xml->params->children() as $param) {
if (!isset($param->value)) {
$this->_fault = new Zend_XmlRpc_Fault(633);
$this->_fault->setEncoding($this->getEncoding());
return false;
}
try {
$param = Zend_XmlRpc_Value::getXmlRpcValue($param->value, Zend_XmlRpc_Value::XML_STRING);
$types[] = $param->getType();
$argv[] = $param->getValue();
} catch (Exception $e) {
$this->_fault = new Zend_XmlRpc_Fault(636);
$this->_fault->setEncoding($this->getEncoding());
return false;
}
}
$this->_types = $types;
$this->_params = $argv;
}
$this->_xml = $request;
return true;
}
/**
* Does the current request contain errors and should it return a fault
* response?
*
* @return boolean
*/
public function isFault()
{
return $this->_fault instanceof Zend_XmlRpc_Fault;
}
/**
* Retrieve the fault response, if any
*
* @return null|Zend_XmlRpc_Fault
*/
public function getFault()
{
return $this->_fault;
}
/**
* Retrieve method parameters as XMLRPC values
*
* @return array
*/
protected function _getXmlRpcParams()
{
$params = array();
if (is_array($this->_xmlRpcParams)) {
foreach ($this->_xmlRpcParams as $param) {
$value = $param['value'];
$type = isset($param['type']) ? $param['type'] : Zend_XmlRpc_Value::AUTO_DETECT_TYPE;
if (!$value instanceof Zend_XmlRpc_Value) {
$value = Zend_XmlRpc_Value::getXmlRpcValue($value, $type);
}
$params[] = $value;
}
}
return $params;
}
/**
* Create XML request
*
* @return string
*/
public function saveXml()
{
$args = $this->_getXmlRpcParams();
$method = $this->getMethod();
$generator = Zend_XmlRpc_Value::getGenerator();
$generator->openElement('methodCall')
->openElement('methodName', $method)
->closeElement('methodName');
if (is_array($args) && count($args)) {
$generator->openElement('params');
foreach ($args as $arg) {
$generator->openElement('param');
$arg->generateXml();
$generator->closeElement('param');
}
$generator->closeElement('params');
}
$generator->closeElement('methodCall');
return $generator->flush();
}
/**
* Return XML request
*
* @return string
*/
public function __toString()
{
return $this->saveXML();
}
}

View file

@ -0,0 +1,124 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Controller
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_XmlRpc_Request
*/
require_once 'Zend/XmlRpc/Request.php';
/**
* XmlRpc Request object -- Request via HTTP
*
* Extends {@link Zend_XmlRpc_Request} to accept a request via HTTP. Request is
* built at construction time using a raw POST; if no data is available, the
* request is declared a fault.
*
* @category Zend
* @package Zend_XmlRpc
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Http.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_XmlRpc_Request_Http extends Zend_XmlRpc_Request
{
/**
* Array of headers
* @var array
*/
protected $_headers;
/**
* Raw XML as received via request
* @var string
*/
protected $_xml;
/**
* Constructor
*
* Attempts to read from php://input to get raw POST request; if an error
* occurs in doing so, or if the XML is invalid, the request is declared a
* fault.
*
* @return void
*/
public function __construct()
{
$xml = @file_get_contents('php://input');
if (!$xml) {
require_once 'Zend/XmlRpc/Fault.php';
$this->_fault = new Zend_XmlRpc_Fault(630);
return;
}
$this->_xml = $xml;
$this->loadXml($xml);
}
/**
* Retrieve the raw XML request
*
* @return string
*/
public function getRawRequest()
{
return $this->_xml;
}
/**
* Get headers
*
* Gets all headers as key => value pairs and returns them.
*
* @return array
*/
public function getHeaders()
{
if (null === $this->_headers) {
$this->_headers = array();
foreach ($_SERVER as $key => $value) {
if ('HTTP_' == substr($key, 0, 5)) {
$header = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($key, 5)))));
$this->_headers[$header] = $value;
}
}
}
return $this->_headers;
}
/**
* Retrieve the full HTTP request, including headers and XML
*
* @return string
*/
public function getFullRequest()
{
$request = '';
foreach ($this->getHeaders() as $key => $value) {
$request .= $key . ': ' . $value . "\n";
}
$request .= $this->_xml;
return $request;
}
}

View file

@ -0,0 +1,84 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Controller
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_XmlRpc_Request
*/
require_once 'Zend/XmlRpc/Request.php';
/**
* XmlRpc Request object -- Request via STDIN
*
* Extends {@link Zend_XmlRpc_Request} to accept a request via STDIN. Request is
* built at construction time using data from STDIN; if no data is available, the
* request is declared a fault.
*
* @category Zend
* @package Zend_XmlRpc
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Stdin.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_XmlRpc_Request_Stdin extends Zend_XmlRpc_Request
{
/**
* Raw XML as received via request
* @var string
*/
protected $_xml;
/**
* Constructor
*
* Attempts to read from php://stdin to get raw POST request; if an error
* occurs in doing so, or if the XML is invalid, the request is declared a
* fault.
*
* @return void
*/
public function __construct()
{
$fh = fopen('php://stdin', 'r');
if (!$fh) {
$this->_fault = new Zend_XmlRpc_Server_Exception(630);
return;
}
$xml = '';
while (!feof($fh)) {
$xml .= fgets($fh);
}
fclose($fh);
$this->_xml = $xml;
$this->loadXml($xml);
}
/**
* Retrieve the raw XML request
*
* @return string
*/
public function getRawRequest()
{
return $this->_xml;
}
}

View file

@ -0,0 +1,248 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Controller
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_XmlRpc_Value
*/
require_once 'Zend/XmlRpc/Value.php';
/**
* Zend_XmlRpc_Fault
*/
require_once 'Zend/XmlRpc/Fault.php';
/**
* XmlRpc Response
*
* Container for accessing an XMLRPC return value and creating the XML response.
*
* @category Zend
* @package Zend_XmlRpc
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Response.php 20208 2010-01-11 22:37:37Z lars $
*/
class Zend_XmlRpc_Response
{
/**
* Return value
* @var mixed
*/
protected $_return;
/**
* Return type
* @var string
*/
protected $_type;
/**
* Response character encoding
* @var string
*/
protected $_encoding = 'UTF-8';
/**
* Fault, if response is a fault response
* @var null|Zend_XmlRpc_Fault
*/
protected $_fault = null;
/**
* Constructor
*
* Can optionally pass in the return value and type hinting; otherwise, the
* return value can be set via {@link setReturnValue()}.
*
* @param mixed $return
* @param string $type
* @return void
*/
public function __construct($return = null, $type = null)
{
$this->setReturnValue($return, $type);
}
/**
* Set encoding to use in response
*
* @param string $encoding
* @return Zend_XmlRpc_Response
*/
public function setEncoding($encoding)
{
$this->_encoding = $encoding;
Zend_XmlRpc_Value::setEncoding($encoding);
return $this;
}
/**
* Retrieve current response encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* Set the return value
*
* Sets the return value, with optional type hinting if provided.
*
* @param mixed $value
* @param string $type
* @return void
*/
public function setReturnValue($value, $type = null)
{
$this->_return = $value;
$this->_type = (string) $type;
}
/**
* Retrieve the return value
*
* @return mixed
*/
public function getReturnValue()
{
return $this->_return;
}
/**
* Retrieve the XMLRPC value for the return value
*
* @return Zend_XmlRpc_Value
*/
protected function _getXmlRpcReturn()
{
return Zend_XmlRpc_Value::getXmlRpcValue($this->_return);
}
/**
* Is the response a fault response?
*
* @return boolean
*/
public function isFault()
{
return $this->_fault instanceof Zend_XmlRpc_Fault;
}
/**
* Returns the fault, if any.
*
* @return null|Zend_XmlRpc_Fault
*/
public function getFault()
{
return $this->_fault;
}
/**
* Load a response from an XML response
*
* Attempts to load a response from an XMLRPC response, autodetecting if it
* is a fault response.
*
* @param string $response
* @return boolean True if a valid XMLRPC response, false if a fault
* response or invalid input
*/
public function loadXml($response)
{
if (!is_string($response)) {
$this->_fault = new Zend_XmlRpc_Fault(650);
$this->_fault->setEncoding($this->getEncoding());
return false;
}
try {
$xml = new SimpleXMLElement($response);
} catch (Exception $e) {
// Not valid XML
$this->_fault = new Zend_XmlRpc_Fault(651);
$this->_fault->setEncoding($this->getEncoding());
return false;
}
if (!empty($xml->fault)) {
// fault response
$this->_fault = new Zend_XmlRpc_Fault();
$this->_fault->setEncoding($this->getEncoding());
$this->_fault->loadXml($response);
return false;
}
if (empty($xml->params)) {
// Invalid response
$this->_fault = new Zend_XmlRpc_Fault(652);
$this->_fault->setEncoding($this->getEncoding());
return false;
}
try {
if (!isset($xml->params) || !isset($xml->params->param) || !isset($xml->params->param->value)) {
throw new Zend_XmlRpc_Value_Exception('Missing XML-RPC value in XML');
}
$valueXml = $xml->params->param->value->asXML();
$value = Zend_XmlRpc_Value::getXmlRpcValue($valueXml, Zend_XmlRpc_Value::XML_STRING);
} catch (Zend_XmlRpc_Value_Exception $e) {
$this->_fault = new Zend_XmlRpc_Fault(653);
$this->_fault->setEncoding($this->getEncoding());
return false;
}
$this->setReturnValue($value->getValue());
return true;
}
/**
* Return response as XML
*
* @return string
*/
public function saveXml()
{
$value = $this->_getXmlRpcReturn();
$generator = Zend_XmlRpc_Value::getGenerator();
$generator->openElement('methodResponse')
->openElement('params')
->openElement('param');
$value->generateXml();
$generator->closeElement('param')
->closeElement('params')
->closeElement('methodResponse');
return $generator->flush();
}
/**
* Return XML response
*
* @return string
*/
public function __toString()
{
return $this->saveXML();
}
}

View file

@ -0,0 +1,51 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Controller
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_XmlRpc_Response
*/
require_once 'Zend/XmlRpc/Response.php';
/**
* HTTP response
*
* @uses Zend_XmlRpc_Response
* @category Zend
* @package Zend_XmlRpc
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Http.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_XmlRpc_Response_Http extends Zend_XmlRpc_Response
{
/**
* Override __toString() to send HTTP Content-Type header
*
* @return string
*/
public function __toString()
{
if (!headers_sent()) {
header('Content-Type: text/xml; charset=' . strtolower($this->getEncoding()));
}
return parent::__toString();
}
}

View file

@ -0,0 +1,615 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Server
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Server.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Extends Zend_Server_Abstract
*/
require_once 'Zend/Server/Abstract.php';
/**
* XMLRPC Request
*/
require_once 'Zend/XmlRpc/Request.php';
/**
* XMLRPC Response
*/
require_once 'Zend/XmlRpc/Response.php';
/**
* XMLRPC HTTP Response
*/
require_once 'Zend/XmlRpc/Response/Http.php';
/**
* XMLRPC server fault class
*/
require_once 'Zend/XmlRpc/Server/Fault.php';
/**
* XMLRPC server system methods class
*/
require_once 'Zend/XmlRpc/Server/System.php';
/**
* Convert PHP to and from xmlrpc native types
*/
require_once 'Zend/XmlRpc/Value.php';
/**
* Reflection API for function/method introspection
*/
require_once 'Zend/Server/Reflection.php';
/**
* Zend_Server_Reflection_Function_Abstract
*/
require_once 'Zend/Server/Reflection/Function/Abstract.php';
/**
* Specifically grab the Zend_Server_Reflection_Method for manually setting up
* system.* methods and handling callbacks in {@link loadFunctions()}.
*/
require_once 'Zend/Server/Reflection/Method.php';
/**
* An XML-RPC server implementation
*
* Example:
* <code>
* require_once 'Zend/XmlRpc/Server.php';
* require_once 'Zend/XmlRpc/Server/Cache.php';
* require_once 'Zend/XmlRpc/Server/Fault.php';
* require_once 'My/Exception.php';
* require_once 'My/Fault/Observer.php';
*
* // Instantiate server
* $server = new Zend_XmlRpc_Server();
*
* // Allow some exceptions to report as fault responses:
* Zend_XmlRpc_Server_Fault::attachFaultException('My_Exception');
* Zend_XmlRpc_Server_Fault::attachObserver('My_Fault_Observer');
*
* // Get or build dispatch table:
* if (!Zend_XmlRpc_Server_Cache::get($filename, $server)) {
* require_once 'Some/Service/Class.php';
* require_once 'Another/Service/Class.php';
*
* // Attach Some_Service_Class in 'some' namespace
* $server->setClass('Some_Service_Class', 'some');
*
* // Attach Another_Service_Class in 'another' namespace
* $server->setClass('Another_Service_Class', 'another');
*
* // Create dispatch table cache file
* Zend_XmlRpc_Server_Cache::save($filename, $server);
* }
*
* $response = $server->handle();
* echo $response;
* </code>
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Server
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Server extends Zend_Server_Abstract
{
/**
* Character encoding
* @var string
*/
protected $_encoding = 'UTF-8';
/**
* Request processed
* @var null|Zend_XmlRpc_Request
*/
protected $_request = null;
/**
* Class to use for responses; defaults to {@link Zend_XmlRpc_Response_Http}
* @var string
*/
protected $_responseClass = 'Zend_XmlRpc_Response_Http';
/**
* Dispatch table of name => method pairs
* @var Zend_Server_Definition
*/
protected $_table;
/**
* PHP types => XML-RPC types
* @var array
*/
protected $_typeMap = array(
'i4' => 'i4',
'int' => 'int',
'integer' => 'int',
'Zend_Crypt_Math_BigInteger' => 'i8',
'i8' => 'i8',
'ex:i8' => 'i8',
'double' => 'double',
'float' => 'double',
'real' => 'double',
'boolean' => 'boolean',
'bool' => 'boolean',
'true' => 'boolean',
'false' => 'boolean',
'string' => 'string',
'str' => 'string',
'base64' => 'base64',
'dateTime.iso8601' => 'dateTime.iso8601',
'date' => 'dateTime.iso8601',
'time' => 'dateTime.iso8601',
'time' => 'dateTime.iso8601',
'Zend_Date' => 'dateTime.iso8601',
'DateTime' => 'dateTime.iso8601',
'array' => 'array',
'struct' => 'struct',
'null' => 'nil',
'nil' => 'nil',
'ex:nil' => 'nil',
'void' => 'void',
'mixed' => 'struct',
);
/**
* Send arguments to all methods or just constructor?
*
* @var bool
*/
protected $_sendArgumentsToAllMethods = true;
/**
* Constructor
*
* Creates system.* methods.
*
* @return void
*/
public function __construct()
{
$this->_table = new Zend_Server_Definition();
$this->_registerSystemMethods();
}
/**
* Proxy calls to system object
*
* @param string $method
* @param array $params
* @return mixed
* @throws Zend_XmlRpc_Server_Exception
*/
public function __call($method, $params)
{
$system = $this->getSystem();
if (!method_exists($system, $method)) {
require_once 'Zend/XmlRpc/Server/Exception.php';
throw new Zend_XmlRpc_Server_Exception('Unknown instance method called on server: ' . $method);
}
return call_user_func_array(array($system, $method), $params);
}
/**
* Attach a callback as an XMLRPC method
*
* Attaches a callback as an XMLRPC method, prefixing the XMLRPC method name
* with $namespace, if provided. Reflection is done on the callback's
* docblock to create the methodHelp for the XMLRPC method.
*
* Additional arguments to pass to the function at dispatch may be passed;
* any arguments following the namespace will be aggregated and passed at
* dispatch time.
*
* @param string|array $function Valid callback
* @param string $namespace Optional namespace prefix
* @return void
* @throws Zend_XmlRpc_Server_Exception
*/
public function addFunction($function, $namespace = '')
{
if (!is_string($function) && !is_array($function)) {
require_once 'Zend/XmlRpc/Server/Exception.php';
throw new Zend_XmlRpc_Server_Exception('Unable to attach function; invalid', 611);
}
$argv = null;
if (2 < func_num_args()) {
$argv = func_get_args();
$argv = array_slice($argv, 2);
}
$function = (array) $function;
foreach ($function as $func) {
if (!is_string($func) || !function_exists($func)) {
require_once 'Zend/XmlRpc/Server/Exception.php';
throw new Zend_XmlRpc_Server_Exception('Unable to attach function; invalid', 611);
}
$reflection = Zend_Server_Reflection::reflectFunction($func, $argv, $namespace);
$this->_buildSignature($reflection);
}
}
/**
* Attach class methods as XMLRPC method handlers
*
* $class may be either a class name or an object. Reflection is done on the
* class or object to determine the available public methods, and each is
* attached to the server as an available method; if a $namespace has been
* provided, that namespace is used to prefix the XMLRPC method names.
*
* Any additional arguments beyond $namespace will be passed to a method at
* invocation.
*
* @param string|object $class
* @param string $namespace Optional
* @param mixed $argv Optional arguments to pass to methods
* @return void
* @throws Zend_XmlRpc_Server_Exception on invalid input
*/
public function setClass($class, $namespace = '', $argv = null)
{
if (is_string($class) && !class_exists($class)) {
require_once 'Zend/XmlRpc/Server/Exception.php';
throw new Zend_XmlRpc_Server_Exception('Invalid method class', 610);
}
$argv = null;
if (2 < func_num_args()) {
$argv = func_get_args();
$argv = array_slice($argv, 2);
}
$dispatchable = Zend_Server_Reflection::reflectClass($class, $argv, $namespace);
foreach ($dispatchable->getMethods() as $reflection) {
$this->_buildSignature($reflection, $class);
}
}
/**
* Raise an xmlrpc server fault
*
* @param string|Exception $fault
* @param int $code
* @return Zend_XmlRpc_Server_Fault
*/
public function fault($fault = null, $code = 404)
{
if (!$fault instanceof Exception) {
$fault = (string) $fault;
if (empty($fault)) {
$fault = 'Unknown Error';
}
require_once 'Zend/XmlRpc/Server/Exception.php';
$fault = new Zend_XmlRpc_Server_Exception($fault, $code);
}
return Zend_XmlRpc_Server_Fault::getInstance($fault);
}
/**
* Handle an xmlrpc call
*
* @param Zend_XmlRpc_Request $request Optional
* @return Zend_XmlRpc_Response|Zend_XmlRpc_Fault
*/
public function handle($request = false)
{
// Get request
if ((!$request || !$request instanceof Zend_XmlRpc_Request)
&& (null === ($request = $this->getRequest()))
) {
require_once 'Zend/XmlRpc/Request/Http.php';
$request = new Zend_XmlRpc_Request_Http();
$request->setEncoding($this->getEncoding());
}
$this->setRequest($request);
if ($request->isFault()) {
$response = $request->getFault();
} else {
try {
$response = $this->_handle($request);
} catch (Exception $e) {
$response = $this->fault($e);
}
}
// Set output encoding
$response->setEncoding($this->getEncoding());
return $response;
}
/**
* Load methods as returned from {@link getFunctions}
*
* Typically, you will not use this method; it will be called using the
* results pulled from {@link Zend_XmlRpc_Server_Cache::get()}.
*
* @param array|Zend_Server_Definition $definition
* @return void
* @throws Zend_XmlRpc_Server_Exception on invalid input
*/
public function loadFunctions($definition)
{
if (!is_array($definition) && (!$definition instanceof Zend_Server_Definition)) {
if (is_object($definition)) {
$type = get_class($definition);
} else {
$type = gettype($definition);
}
require_once 'Zend/XmlRpc/Server/Exception.php';
throw new Zend_XmlRpc_Server_Exception('Unable to load server definition; must be an array or Zend_Server_Definition, received ' . $type, 612);
}
$this->_table->clearMethods();
$this->_registerSystemMethods();
if ($definition instanceof Zend_Server_Definition) {
$definition = $definition->getMethods();
}
foreach ($definition as $key => $method) {
if ('system.' == substr($key, 0, 7)) {
continue;
}
$this->_table->addMethod($method, $key);
}
}
/**
* Set encoding
*
* @param string $encoding
* @return Zend_XmlRpc_Server
*/
public function setEncoding($encoding)
{
$this->_encoding = $encoding;
Zend_XmlRpc_Value::setEncoding($encoding);
return $this;
}
/**
* Retrieve current encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* Do nothing; persistence is handled via {@link Zend_XmlRpc_Server_Cache}
*
* @param mixed $mode
* @return void
*/
public function setPersistence($mode)
{
}
/**
* Set the request object
*
* @param string|Zend_XmlRpc_Request $request
* @return Zend_XmlRpc_Server
* @throws Zend_XmlRpc_Server_Exception on invalid request class or object
*/
public function setRequest($request)
{
if (is_string($request) && class_exists($request)) {
$request = new $request();
if (!$request instanceof Zend_XmlRpc_Request) {
require_once 'Zend/XmlRpc/Server/Exception.php';
throw new Zend_XmlRpc_Server_Exception('Invalid request class');
}
$request->setEncoding($this->getEncoding());
} elseif (!$request instanceof Zend_XmlRpc_Request) {
require_once 'Zend/XmlRpc/Server/Exception.php';
throw new Zend_XmlRpc_Server_Exception('Invalid request object');
}
$this->_request = $request;
return $this;
}
/**
* Return currently registered request object
*
* @return null|Zend_XmlRpc_Request
*/
public function getRequest()
{
return $this->_request;
}
/**
* Set the class to use for the response
*
* @param string $class
* @return boolean True if class was set, false if not
*/
public function setResponseClass($class)
{
if (!class_exists($class) or
($c = new ReflectionClass($class) and !$c->isSubclassOf('Zend_XmlRpc_Response'))) {
require_once 'Zend/XmlRpc/Server/Exception.php';
throw new Zend_XmlRpc_Server_Exception('Invalid response class');
}
$this->_responseClass = $class;
return true;
}
/**
* Retrieve current response class
*
* @return string
*/
public function getResponseClass()
{
return $this->_responseClass;
}
/**
* Retrieve dispatch table
*
* @return array
*/
public function getDispatchTable()
{
return $this->_table;
}
/**
* Returns a list of registered methods
*
* Returns an array of dispatchables (Zend_Server_Reflection_Function,
* _Method, and _Class items).
*
* @return array
*/
public function getFunctions()
{
return $this->_table->toArray();
}
/**
* Retrieve system object
*
* @return Zend_XmlRpc_Server_System
*/
public function getSystem()
{
return $this->_system;
}
/**
* Send arguments to all methods?
*
* If setClass() is used to add classes to the server, this flag defined
* how to handle arguments. If set to true, all methods including constructor
* will receive the arguments. If set to false, only constructor will receive the
* arguments
*/
public function sendArgumentsToAllMethods($flag = null)
{
if ($flag === null) {
return $this->_sendArgumentsToAllMethods;
}
$this->_sendArgumentsToAllMethods = (bool)$flag;
return $this;
}
/**
* Map PHP type to XML-RPC type
*
* @param string $type
* @return string
*/
protected function _fixType($type)
{
if (isset($this->_typeMap[$type])) {
return $this->_typeMap[$type];
}
return 'void';
}
/**
* Handle an xmlrpc call (actual work)
*
* @param Zend_XmlRpc_Request $request
* @return Zend_XmlRpc_Response
* @throws Zend_XmlRpcServer_Exception|Exception
* Zend_XmlRpcServer_Exceptions are thrown for internal errors; otherwise,
* any other exception may be thrown by the callback
*/
protected function _handle(Zend_XmlRpc_Request $request)
{
$method = $request->getMethod();
// Check for valid method
if (!$this->_table->hasMethod($method)) {
require_once 'Zend/XmlRpc/Server/Exception.php';
throw new Zend_XmlRpc_Server_Exception('Method "' . $method . '" does not exist', 620);
}
$info = $this->_table->getMethod($method);
$params = $request->getParams();
$argv = $info->getInvokeArguments();
if (0 < count($argv) and $this->sendArgumentsToAllMethods()) {
$params = array_merge($params, $argv);
}
// Check calling parameters against signatures
$matched = false;
$sigCalled = $request->getTypes();
$sigLength = count($sigCalled);
$paramsLen = count($params);
if ($sigLength < $paramsLen) {
for ($i = $sigLength; $i < $paramsLen; ++$i) {
$xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($params[$i]);
$sigCalled[] = $xmlRpcValue->getType();
}
}
$signatures = $info->getPrototypes();
foreach ($signatures as $signature) {
$sigParams = $signature->getParameters();
if ($sigCalled === $sigParams) {
$matched = true;
break;
}
}
if (!$matched) {
require_once 'Zend/XmlRpc/Server/Exception.php';
throw new Zend_XmlRpc_Server_Exception('Calling parameters do not match signature', 623);
}
$return = $this->_dispatch($info, $params);
$responseClass = $this->getResponseClass();
return new $responseClass($return);
}
/**
* Register system methods with the server
*
* @return void
*/
protected function _registerSystemMethods()
{
$system = new Zend_XmlRpc_Server_System($this);
$this->_system = $system;
$this->setClass($system, 'system');
}
}

View file

@ -0,0 +1,46 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Server
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Cache.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Server_Cache */
require_once 'Zend/Server/Cache.php';
/**
* Zend_XmlRpc_Server_Cache: cache Zend_XmlRpc_Server server definition
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Server
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Server_Cache extends Zend_Server_Cache
{
/**
* @var array Skip system methods when caching XML-RPC server
*/
protected static $_skipMethods = array(
'system.listMethods',
'system.methodHelp',
'system.methodSignature',
'system.multicall',
);
}

View file

@ -0,0 +1,42 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Server
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Zend_XmlRpc_Exception
*/
require_once 'Zend/XmlRpc/Exception.php';
/**
* Zend_XmlRpc_Server_Exception
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Server
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Server_Exception extends Zend_XmlRpc_Exception
{
}

View file

@ -0,0 +1,201 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Server
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Fault.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Zend_XmlRpc_Fault
*/
require_once 'Zend/XmlRpc/Fault.php';
/**
* XMLRPC Server Faults
*
* Encapsulates an exception for use as an XMLRPC fault response. Valid
* exception classes that may be used for generating the fault code and fault
* string can be attached using {@link attachFaultException()}; all others use a
* generic '404 Unknown error' response.
*
* You may also attach fault observers, which would allow you to monitor
* particular fault cases; this is done via {@link attachObserver()}. Observers
* need only implement a static 'observe' method.
*
* To allow method chaining, you may use the {@link getInstance()} factory
* to instantiate a Zend_XmlRpc_Server_Fault.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Server
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Server_Fault extends Zend_XmlRpc_Fault
{
/**
* @var Exception
*/
protected $_exception;
/**
* @var array Array of exception classes that may define xmlrpc faults
*/
protected static $_faultExceptionClasses = array('Zend_XmlRpc_Server_Exception' => true);
/**
* @var array Array of fault observers
*/
protected static $_observers = array();
/**
* Constructor
*
* @param Exception $e
* @return Zend_XmlRpc_Server_Fault
*/
public function __construct(Exception $e)
{
$this->_exception = $e;
$code = 404;
$message = 'Unknown error';
$exceptionClass = get_class($e);
foreach (array_keys(self::$_faultExceptionClasses) as $class) {
if ($e instanceof $class) {
$code = $e->getCode();
$message = $e->getMessage();
break;
}
}
parent::__construct($code, $message);
// Notify exception observers, if present
if (!empty(self::$_observers)) {
foreach (array_keys(self::$_observers) as $observer) {
call_user_func(array($observer, 'observe'), $this);
}
}
}
/**
* Return Zend_XmlRpc_Server_Fault instance
*
* @param Exception $e
* @return Zend_XmlRpc_Server_Fault
*/
public static function getInstance(Exception $e)
{
return new self($e);
}
/**
* Attach valid exceptions that can be used to define xmlrpc faults
*
* @param string|array $classes Class name or array of class names
* @return void
*/
public static function attachFaultException($classes)
{
if (!is_array($classes)) {
$classes = (array) $classes;
}
foreach ($classes as $class) {
if (is_string($class) && class_exists($class)) {
self::$_faultExceptionClasses[$class] = true;
}
}
}
/**
* Detach fault exception classes
*
* @param string|array $classes Class name or array of class names
* @return void
*/
public static function detachFaultException($classes)
{
if (!is_array($classes)) {
$classes = (array) $classes;
}
foreach ($classes as $class) {
if (is_string($class) && isset(self::$_faultExceptionClasses[$class])) {
unset(self::$_faultExceptionClasses[$class]);
}
}
}
/**
* Attach an observer class
*
* Allows observation of xmlrpc server faults, thus allowing logging or mail
* notification of fault responses on the xmlrpc server.
*
* Expects a valid class name; that class must have a public static method
* 'observe' that accepts an exception as its sole argument.
*
* @param string $class
* @return boolean
*/
public static function attachObserver($class)
{
if (!is_string($class)
|| !class_exists($class)
|| !is_callable(array($class, 'observe')))
{
return false;
}
if (!isset(self::$_observers[$class])) {
self::$_observers[$class] = true;
}
return true;
}
/**
* Detach an observer
*
* @param string $class
* @return boolean
*/
public static function detachObserver($class)
{
if (!isset(self::$_observers[$class])) {
return false;
}
unset(self::$_observers[$class]);
return true;
}
/**
* Retrieve the exception
*
* @access public
* @return Exception
*/
public function getException()
{
return $this->_exception;
}
}

View file

@ -0,0 +1,162 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Server
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: System.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* XML-RPC system.* methods
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Server
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Server_System
{
/**
* @var Zend_XmlRpc_Server
*/
protected $_server;
/**
* Constructor
*
* @param Zend_XmlRpc_Server $server
* @return void
*/
public function __construct(Zend_XmlRpc_Server $server)
{
$this->_server = $server;
}
/**
* List all available XMLRPC methods
*
* Returns an array of methods.
*
* @return array
*/
public function listMethods()
{
$table = $this->_server->getDispatchTable()->getMethods();
return array_keys($table);
}
/**
* Display help message for an XMLRPC method
*
* @param string $method
* @return string
*/
public function methodHelp($method)
{
$table = $this->_server->getDispatchTable();
if (!$table->hasMethod($method)) {
require_once 'Zend/XmlRpc/Server/Exception.php';
throw new Zend_XmlRpc_Server_Exception('Method "' . $method . '" does not exist', 640);
}
return $table->getMethod($method)->getMethodHelp();
}
/**
* Return a method signature
*
* @param string $method
* @return array
*/
public function methodSignature($method)
{
$table = $this->_server->getDispatchTable();
if (!$table->hasMethod($method)) {
require_once 'Zend/XmlRpc/Server/Exception.php';
throw new Zend_XmlRpc_Server_Exception('Method "' . $method . '" does not exist', 640);
}
$method = $table->getMethod($method)->toArray();
return $method['prototypes'];
}
/**
* Multicall - boxcar feature of XML-RPC for calling multiple methods
* in a single request.
*
* Expects a an array of structs representing method calls, each element
* having the keys:
* - methodName
* - params
*
* Returns an array of responses, one for each method called, with the value
* returned by the method. If an error occurs for a given method, returns a
* struct with a fault response.
*
* @see http://www.xmlrpc.com/discuss/msgReader$1208
* @param array $methods
* @return array
*/
public function multicall($methods)
{
$responses = array();
foreach ($methods as $method) {
$fault = false;
if (!is_array($method)) {
$fault = $this->_server->fault('system.multicall expects each method to be a struct', 601);
} elseif (!isset($method['methodName'])) {
$fault = $this->_server->fault('Missing methodName: ' . var_export($methods, 1), 602);
} elseif (!isset($method['params'])) {
$fault = $this->_server->fault('Missing params', 603);
} elseif (!is_array($method['params'])) {
$fault = $this->_server->fault('Params must be an array', 604);
} else {
if ('system.multicall' == $method['methodName']) {
// don't allow recursive calls to multicall
$fault = $this->_server->fault('Recursive system.multicall forbidden', 605);
}
}
if (!$fault) {
try {
$request = new Zend_XmlRpc_Request();
$request->setMethod($method['methodName']);
$request->setParams($method['params']);
$response = $this->_server->handle($request);
if ($response instanceof Zend_XmlRpc_Fault
|| $response->isFault()
) {
$fault = $response;
} else {
$responses[] = $response->getReturnValue();
}
} catch (Exception $e) {
$fault = $this->_server->fault($e);
}
}
if ($fault) {
$responses[] = array(
'faultCode' => $fault->getCode(),
'faultString' => $fault->getMessage()
);
}
}
return $responses;
}
}

View file

@ -0,0 +1,485 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Value.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Represent a native XML-RPC value entity, used as parameters for the methods
* called by the Zend_XmlRpc_Client object and as the return value for those calls.
*
* This object as a very important static function Zend_XmlRpc_Value::getXmlRpcValue, this
* function acts likes a factory for the Zend_XmlRpc_Value objects
*
* Using this function, users/Zend_XmlRpc_Client object can create the Zend_XmlRpc_Value objects
* from PHP variables, XML string or by specifing the exact XML-RPC natvie type
*
* @package Zend_XmlRpc
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_XmlRpc_Value
{
/**
* The native XML-RPC representation of this object's value
*
* If the native type of this object is array or struct, this will be an array
* of Zend_XmlRpc_Value objects
*/
protected $_value;
/**
* The native XML-RPC type of this object
* One of the XMLRPC_TYPE_* constants
*/
protected $_type;
/**
* XML code representation of this object (will be calculated only once)
*/
protected $_xml;
/**
* @var Zend_XmlRpc_Generator_GeneratorAbstract
*/
protected static $_generator;
/**
* Specify that the XML-RPC native type will be auto detected from a PHP variable type
*/
const AUTO_DETECT_TYPE = 'auto_detect';
/**
* Specify that the XML-RPC value will be parsed out from a given XML code
*/
const XML_STRING = 'xml';
/**
* All the XML-RPC native types
*/
const XMLRPC_TYPE_I4 = 'i4';
const XMLRPC_TYPE_INTEGER = 'int';
const XMLRPC_TYPE_I8 = 'i8';
const XMLRPC_TYPE_APACHEI8 = 'ex:i8';
const XMLRPC_TYPE_DOUBLE = 'double';
const XMLRPC_TYPE_BOOLEAN = 'boolean';
const XMLRPC_TYPE_STRING = 'string';
const XMLRPC_TYPE_DATETIME = 'dateTime.iso8601';
const XMLRPC_TYPE_BASE64 = 'base64';
const XMLRPC_TYPE_ARRAY = 'array';
const XMLRPC_TYPE_STRUCT = 'struct';
const XMLRPC_TYPE_NIL = 'nil';
const XMLRPC_TYPE_APACHENIL = 'ex:nil';
/**
* Get the native XML-RPC type (the type is one of the Zend_XmlRpc_Value::XMLRPC_TYPE_* constants)
*
* @return string
*/
public function getType()
{
return $this->_type;
}
/**
* Get XML generator instance
*
* @return Zend_XmlRpc_Generator_GeneratorAbstract
*/
public static function getGenerator()
{
if (!self::$_generator) {
if (extension_loaded('xmlwriter')) {
require_once 'Zend/XmlRpc/Generator/XmlWriter.php';
self::$_generator = new Zend_XmlRpc_Generator_XmlWriter();
} else {
require_once 'Zend/XmlRpc/Generator/DomDocument.php';
self::$_generator = new Zend_XmlRpc_Generator_DomDocument();
}
}
return self::$_generator;
}
/**
* Sets XML generator instance
*
* @param Zend_XmlRpc_Generator_GeneratorAbstract $generator
* @return void
*/
public static function setGenerator(Zend_XmlRpc_Generator_GeneratorAbstract $generator)
{
self::$_generator = $generator;
}
/**
* Changes the encoding of the generator
*
* @param string $encoding
* @return void
*/
public static function setEncoding($encoding)
{
$generator = self::getGenerator();
$newGenerator = new $generator($encoding);
self::setGenerator($newGenerator);
}
/**
* Return the value of this object, convert the XML-RPC native value into a PHP variable
*
* @return mixed
*/
abstract public function getValue();
/**
* Return the XML code that represent a native MXL-RPC value
*
* @return string
*/
public function saveXml()
{
if (!$this->_xml) {
$this->generateXml();
}
return $this->_xml;
}
/**
* Generate XML code that represent a native XML/RPC value
*
* @return void
*/
public function generateXml()
{
if (!$this->_xml) {
$this->_generateXml();
}
}
/**
* Creates a Zend_XmlRpc_Value* object, representing a native XML-RPC value
* A XmlRpcValue object can be created in 3 ways:
* 1. Autodetecting the native type out of a PHP variable
* (if $type is not set or equal to Zend_XmlRpc_Value::AUTO_DETECT_TYPE)
* 2. By specifing the native type ($type is one of the Zend_XmlRpc_Value::XMLRPC_TYPE_* constants)
* 3. From a XML string ($type is set to Zend_XmlRpc_Value::XML_STRING)
*
* By default the value type is autodetected according to it's PHP type
*
* @param mixed $value
* @param Zend_XmlRpc_Value::constant $type
*
* @return Zend_XmlRpc_Value
* @static
*/
public static function getXmlRpcValue($value, $type = self::AUTO_DETECT_TYPE)
{
switch ($type) {
case self::AUTO_DETECT_TYPE:
// Auto detect the XML-RPC native type from the PHP type of $value
return self::_phpVarToNativeXmlRpc($value);
case self::XML_STRING:
// Parse the XML string given in $value and get the XML-RPC value in it
return self::_xmlStringToNativeXmlRpc($value);
case self::XMLRPC_TYPE_I4:
// fall through to the next case
case self::XMLRPC_TYPE_INTEGER:
require_once 'Zend/XmlRpc/Value/Integer.php';
return new Zend_XmlRpc_Value_Integer($value);
case self::XMLRPC_TYPE_I8:
// fall through to the next case
case self::XMLRPC_TYPE_APACHEI8:
require_once 'Zend/XmlRpc/Value/BigInteger.php';
return new Zend_XmlRpc_Value_BigInteger($value);
case self::XMLRPC_TYPE_DOUBLE:
require_once 'Zend/XmlRpc/Value/Double.php';
return new Zend_XmlRpc_Value_Double($value);
case self::XMLRPC_TYPE_BOOLEAN:
require_once 'Zend/XmlRpc/Value/Boolean.php';
return new Zend_XmlRpc_Value_Boolean($value);
case self::XMLRPC_TYPE_STRING:
require_once 'Zend/XmlRpc/Value/String.php';
return new Zend_XmlRpc_Value_String($value);
case self::XMLRPC_TYPE_BASE64:
require_once 'Zend/XmlRpc/Value/Base64.php';
return new Zend_XmlRpc_Value_Base64($value);
case self::XMLRPC_TYPE_NIL:
// fall through to the next case
case self::XMLRPC_TYPE_APACHENIL:
require_once 'Zend/XmlRpc/Value/Nil.php';
return new Zend_XmlRpc_Value_Nil();
case self::XMLRPC_TYPE_DATETIME:
require_once 'Zend/XmlRpc/Value/DateTime.php';
return new Zend_XmlRpc_Value_DateTime($value);
case self::XMLRPC_TYPE_ARRAY:
require_once 'Zend/XmlRpc/Value/Array.php';
return new Zend_XmlRpc_Value_Array($value);
case self::XMLRPC_TYPE_STRUCT:
require_once 'Zend/XmlRpc/Value/Struct.php';
return new Zend_XmlRpc_Value_Struct($value);
default:
require_once 'Zend/XmlRpc/Value/Exception.php';
throw new Zend_XmlRpc_Value_Exception('Given type is not a '. __CLASS__ .' constant');
}
}
/**
* Transform a PHP native variable into a XML-RPC native value
*
* @param mixed $value The PHP variable for convertion
*
* @return Zend_XmlRpc_Value
* @static
*/
protected static function _phpVarToNativeXmlRpc($value)
{
switch (gettype($value)) {
case 'object':
// Check to see if it's an XmlRpc value
if ($value instanceof Zend_XmlRpc_Value) {
return $value;
}
if ($value instanceof Zend_Crypt_Math_BigInteger) {
require_once 'Zend/XmlRpc/Value/BigInteger.php';
return new Zend_XmlRpc_Value_BigInteger($value);
}
if ($value instanceof Zend_Date or $value instanceof DateTime) {
require_once 'Zend/XmlRpc/Value/DateTime.php';
return new Zend_XmlRpc_Value_DateTime($value);
}
// Otherwise, we convert the object into a struct
$value = get_object_vars($value);
// Break intentionally omitted
case 'array':
// Default native type for a PHP array (a simple numeric array) is 'array'
require_once 'Zend/XmlRpc/Value/Array.php';
$obj = 'Zend_XmlRpc_Value_Array';
// Determine if this is an associative array
if (!empty($value) && is_array($value) && (array_keys($value) !== range(0, count($value) - 1))) {
require_once 'Zend/XmlRpc/Value/Struct.php';
$obj = 'Zend_XmlRpc_Value_Struct';
}
return new $obj($value);
case 'integer':
require_once 'Zend/XmlRpc/Value/Integer.php';
return new Zend_XmlRpc_Value_Integer($value);
case 'double':
require_once 'Zend/XmlRpc/Value/Double.php';
return new Zend_XmlRpc_Value_Double($value);
case 'boolean':
require_once 'Zend/XmlRpc/Value/Boolean.php';
return new Zend_XmlRpc_Value_Boolean($value);
case 'NULL':
case 'null':
require_once 'Zend/XmlRpc/Value/Nil.php';
return new Zend_XmlRpc_Value_Nil();
case 'string':
// Fall through to the next case
default:
// If type isn't identified (or identified as string), it treated as string
require_once 'Zend/XmlRpc/Value/String.php';
return new Zend_XmlRpc_Value_String($value);
}
}
/**
* Transform an XML string into a XML-RPC native value
*
* @param string|SimpleXMLElement $xml A SimpleXMLElement object represent the XML string
* It can be also a valid XML string for convertion
*
* @return Zend_XmlRpc_Value
* @static
*/
protected static function _xmlStringToNativeXmlRpc($xml)
{
self::_createSimpleXMLElement($xml);
self::_extractTypeAndValue($xml, $type, $value);
switch ($type) {
// All valid and known XML-RPC native values
case self::XMLRPC_TYPE_I4:
// Fall through to the next case
case self::XMLRPC_TYPE_INTEGER:
require_once 'Zend/XmlRpc/Value/Integer.php';
$xmlrpcValue = new Zend_XmlRpc_Value_Integer($value);
break;
case self::XMLRPC_TYPE_APACHEI8:
// Fall through to the next case
case self::XMLRPC_TYPE_I8:
require_once 'Zend/XmlRpc/Value/BigInteger.php';
$xmlrpcValue = new Zend_XmlRpc_Value_BigInteger($value);
break;
case self::XMLRPC_TYPE_DOUBLE:
require_once 'Zend/XmlRpc/Value/Double.php';
$xmlrpcValue = new Zend_XmlRpc_Value_Double($value);
break;
case self::XMLRPC_TYPE_BOOLEAN:
require_once 'Zend/XmlRpc/Value/Boolean.php';
$xmlrpcValue = new Zend_XmlRpc_Value_Boolean($value);
break;
case self::XMLRPC_TYPE_STRING:
require_once 'Zend/XmlRpc/Value/String.php';
$xmlrpcValue = new Zend_XmlRpc_Value_String($value);
break;
case self::XMLRPC_TYPE_DATETIME: // The value should already be in a iso8601 format
require_once 'Zend/XmlRpc/Value/DateTime.php';
$xmlrpcValue = new Zend_XmlRpc_Value_DateTime($value);
break;
case self::XMLRPC_TYPE_BASE64: // The value should already be base64 encoded
require_once 'Zend/XmlRpc/Value/Base64.php';
$xmlrpcValue = new Zend_XmlRpc_Value_Base64($value, true);
break;
case self::XMLRPC_TYPE_NIL:
// Fall through to the next case
case self::XMLRPC_TYPE_APACHENIL:
// The value should always be NULL
require_once 'Zend/XmlRpc/Value/Nil.php';
$xmlrpcValue = new Zend_XmlRpc_Value_Nil();
break;
case self::XMLRPC_TYPE_ARRAY:
// PHP 5.2.4 introduced a regression in how empty($xml->value)
// returns; need to look for the item specifically
$data = null;
foreach ($value->children() as $key => $value) {
if ('data' == $key) {
$data = $value;
break;
}
}
if (null === $data) {
require_once 'Zend/XmlRpc/Value/Exception.php';
throw new Zend_XmlRpc_Value_Exception('Invalid XML for XML-RPC native '. self::XMLRPC_TYPE_ARRAY .' type: ARRAY tag must contain DATA tag');
}
$values = array();
// Parse all the elements of the array from the XML string
// (simple xml element) to Zend_XmlRpc_Value objects
foreach ($data->value as $element) {
$values[] = self::_xmlStringToNativeXmlRpc($element);
}
require_once 'Zend/XmlRpc/Value/Array.php';
$xmlrpcValue = new Zend_XmlRpc_Value_Array($values);
break;
case self::XMLRPC_TYPE_STRUCT:
$values = array();
// Parse all the memebers of the struct from the XML string
// (simple xml element) to Zend_XmlRpc_Value objects
foreach ($value->member as $member) {
// @todo? If a member doesn't have a <value> tag, we don't add it to the struct
// Maybe we want to throw an exception here ?
if (!isset($member->value) or !isset($member->name)) {
continue;
//throw new Zend_XmlRpc_Value_Exception('Member of the '. self::XMLRPC_TYPE_STRUCT .' XML-RPC native type must contain a VALUE tag');
}
$values[(string)$member->name] = self::_xmlStringToNativeXmlRpc($member->value);
}
require_once 'Zend/XmlRpc/Value/Struct.php';
$xmlrpcValue = new Zend_XmlRpc_Value_Struct($values);
break;
default:
require_once 'Zend/XmlRpc/Value/Exception.php';
throw new Zend_XmlRpc_Value_Exception('Value type \''. $type .'\' parsed from the XML string is not a known XML-RPC native type');
break;
}
$xmlrpcValue->_setXML($xml->asXML());
return $xmlrpcValue;
}
protected static function _createSimpleXMLElement(&$xml)
{
if ($xml instanceof SimpleXMLElement) {
return;
}
try {
$xml = new SimpleXMLElement($xml);
} catch (Exception $e) {
// The given string is not a valid XML
require_once 'Zend/XmlRpc/Value/Exception.php';
throw new Zend_XmlRpc_Value_Exception('Failed to create XML-RPC value from XML string: ' . $e->getMessage(), $e->getCode(), $e);
}
}
/**
* Extract XML/RPC type and value from SimpleXMLElement object
*
* @param SimpleXMLElement $xml
* @param string &$type Type bind variable
* @param string &$value Value bind variable
* @return void
*/
protected static function _extractTypeAndValue(SimpleXMLElement $xml, &$type, &$value)
{
list($type, $value) = each($xml);
if (!$type and $value === null) {
$namespaces = array('ex' => 'http://ws.apache.org/xmlrpc/namespaces/extensions');
foreach ($namespaces as $namespaceName => $namespaceUri) {
$namespaceXml = $xml->children($namespaceUri);
list($type, $value) = each($namespaceXml);
if ($type !== null) {
$type = $namespaceName . ':' . $type;
break;
}
}
}
// If no type was specified, the default is string
if (!$type) {
$type = self::XMLRPC_TYPE_STRING;
}
}
/**
* @param $xml
* @return void
*/
protected function _setXML($xml)
{
$this->_xml = $this->getGenerator()->stripDeclaration($xml);
}
}

View file

@ -0,0 +1,75 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Array.php 20208 2010-01-11 22:37:37Z lars $
*/
/**
* Zend_XmlRpc_Value_Collection
*/
require_once 'Zend/XmlRpc/Value/Collection.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Value_Array extends Zend_XmlRpc_Value_Collection
{
/**
* Set the value of an array native type
*
* @param array $value
*/
public function __construct($value)
{
$this->_type = self::XMLRPC_TYPE_ARRAY;
parent::__construct($value);
}
/**
* Generate the XML code that represent an array native MXL-RPC value
*
* @return void
*/
protected function _generateXml()
{
$generator = $this->getGenerator();
$generator->openElement('value')
->openElement('array')
->openElement('data');
if (is_array($this->_value)) {
foreach ($this->_value as $val) {
$val->generateXml();
}
}
$generator->closeElement('data')
->closeElement('array')
->closeElement('value');
$this->_xml = (string)$generator;
}
}

View file

@ -0,0 +1,68 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Base64.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Zend_XmlRpc_Value_Scalar
*/
require_once 'Zend/XmlRpc/Value/Scalar.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Value_Base64 extends Zend_XmlRpc_Value_Scalar
{
/**
* Set the value of a base64 native type
* We keep this value in base64 encoding
*
* @param string $value
* @param bool $already_encoded If set, it means that the given string is already base64 encoded
*/
public function __construct($value, $alreadyEncoded = false)
{
$this->_type = self::XMLRPC_TYPE_BASE64;
$value = (string)$value; // Make sure this value is string
if (!$alreadyEncoded) {
$value = base64_encode($value); // We encode it in base64
}
$this->_value = $value;
}
/**
* Return the value of this object, convert the XML-RPC native base64 value into a PHP string
* We return this value decoded (a normal string)
*
* @return string
*/
public function getValue()
{
return base64_decode($this->_value);
}
}

View file

@ -0,0 +1,65 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Integer.php 17753 2009-08-22 16:09:37Z lars $
*/
/**
* Zend_XmlRpc_Value_Integer
*/
require_once 'Zend/XmlRpc/Value/Integer.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Value_BigInteger extends Zend_XmlRpc_Value_Integer
{
/**
* @var Zend_Crypt_Math_BigInteger
*/
protected $_integer;
/**
* @param mixed $value
*/
public function __construct($value)
{
require_once 'Zend/Crypt/Math/BigInteger.php';
$this->_integer = new Zend_Crypt_Math_BigInteger();
$this->_value = $this->_integer->init($this->_value);
$this->_type = self::XMLRPC_TYPE_I8;
}
/**
* Return bigint value object
*
* @return Zend_Crypt_Math_BigInteger
*/
public function getValue()
{
return $this->_integer;
}
}

View file

@ -0,0 +1,63 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Boolean.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Zend_XmlRpc_Value_Scalar
*/
require_once 'Zend/XmlRpc/Value/Scalar.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Value_Boolean extends Zend_XmlRpc_Value_Scalar
{
/**
* Set the value of a boolean native type
* We hold the boolean type as an integer (0 or 1)
*
* @param bool $value
*/
public function __construct($value)
{
$this->_type = self::XMLRPC_TYPE_BOOLEAN;
// Make sure the value is boolean and then convert it into a integer
// The double convertion is because a bug in the ZendOptimizer in PHP version 5.0.4
$this->_value = (int)(bool)$value;
}
/**
* Return the value of this object, convert the XML-RPC native boolean value into a PHP boolean
*
* @return bool
*/
public function getValue()
{
return (bool)$this->_value;
}
}

View file

@ -0,0 +1,73 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Collection.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Zend_XmlRpc_Value
*/
require_once 'Zend/XmlRpc/Value.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_XmlRpc_Value_Collection extends Zend_XmlRpc_Value
{
/**
* Set the value of a collection type (array and struct) native types
*
* @param array $value
*/
public function __construct($value)
{
$values = (array)$value; // Make sure that the value is an array
foreach ($values as $key => $value) {
// If the elements of the given array are not Zend_XmlRpc_Value objects,
// we need to convert them as such (using auto-detection from PHP value)
if (!$value instanceof parent) {
$value = self::getXmlRpcValue($value, self::AUTO_DETECT_TYPE);
}
$this->_value[$key] = $value;
}
}
/**
* Return the value of this object, convert the XML-RPC native collection values into a PHP array
*
* @return arary
*/
public function getValue()
{
$values = (array)$this->_value;
foreach ($values as $key => $value) {
/* @var $value Zend_XmlRpc_Value */
$values[$key] = $value->getValue();
}
return $values;
}
}

View file

@ -0,0 +1,91 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DateTime.php 20278 2010-01-14 14:48:59Z ralph $
*/
/**
* Zend_XmlRpc_Value_Scalar
*/
require_once 'Zend/XmlRpc/Value/Scalar.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Value_DateTime extends Zend_XmlRpc_Value_Scalar
{
/**
* PHP compatible format string for XML/RPC datetime values
*
* @var string
*/
protected $_phpFormatString = 'Ymd\\TH:i:s';
/**
* ISO compatible format string for XML/RPC datetime values
*
* @var string
*/
protected $_isoFormatString = 'YYYYMMddTHH:mm:ss';
/**
* Set the value of a dateTime.iso8601 native type
*
* The value is in iso8601 format, minus any timezone information or dashes
*
* @param mixed $value Integer of the unix timestamp or any string that can be parsed
* to a unix timestamp using the PHP strtotime() function
*/
public function __construct($value)
{
$this->_type = self::XMLRPC_TYPE_DATETIME;
if ($value instanceof Zend_Date) {
$this->_value = $value->toString($this->_isoFormatString);
} elseif ($value instanceof DateTime) {
$this->_value = $value->format($this->_phpFormatString);
} elseif (is_numeric($value)) { // The value is numeric, we make sure it is an integer
$this->_value = date($this->_phpFormatString, (int)$value);
} else {
$timestamp = strtotime($value);
if ($timestamp === false || $timestamp == -1) { // cannot convert the value to a timestamp
require_once 'Zend/XmlRpc/Value/Exception.php';
throw new Zend_XmlRpc_Value_Exception('Cannot convert given value \''. $value .'\' to a timestamp');
}
$this->_value = date($this->_phpFormatString, $timestamp); // Convert the timestamp to iso8601 format
}
}
/**
* Return the value of this object as iso8601 dateTime value
*
* @return int As a Unix timestamp
*/
public function getValue()
{
return $this->_value;
}
}

View file

@ -0,0 +1,62 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Double.php 21159 2010-02-23 17:56:52Z matthew $
*/
/**
* Zend_XmlRpc_Value_Scalar
*/
require_once 'Zend/XmlRpc/Value/Scalar.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Value_Double extends Zend_XmlRpc_Value_Scalar
{
/**
* Set the value of a double native type
*
* @param float $value
*/
public function __construct($value)
{
$this->_type = self::XMLRPC_TYPE_DOUBLE;
$precision = (int)ini_get('precision');
$formatString = '%1.' . $precision . 'F';
$this->_value = rtrim(sprintf($formatString, (float)$value), '0');
}
/**
* Return the value of this object, convert the XML-RPC native double value into a PHP float
*
* @return float
*/
public function getValue()
{
return (float)$this->_value;
}
}

View file

@ -0,0 +1,39 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Zend_XmlRpc_Exception
*/
require_once 'Zend/XmlRpc/Exception.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Value_Exception extends Zend_XmlRpc_Exception
{}

View file

@ -0,0 +1,65 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Integer.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Zend_XmlRpc_Value_Scalar
*/
require_once 'Zend/XmlRpc/Value/Scalar.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Value_Integer extends Zend_XmlRpc_Value_Scalar
{
/**
* Set the value of an integer native type
*
* @param int $value
*/
public function __construct($value)
{
if ($value > PHP_INT_MAX) {
require_once 'Zend/XmlRpc/Value/Exception.php';
throw new Zend_XmlRpc_Value_Exception('Overlong integer given');
}
$this->_type = self::XMLRPC_TYPE_INTEGER;
$this->_value = (int)$value; // Make sure this value is integer
}
/**
* Return the value of this object, convert the XML-RPC native integer value into a PHP integer
*
* @return int
*/
public function getValue()
{
return $this->_value;
}
}

View file

@ -0,0 +1,60 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Nil.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Zend_XmlRpc_Value_Scalar
*/
require_once 'Zend/XmlRpc/Value/Scalar.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Value_Nil extends Zend_XmlRpc_Value_Scalar
{
/**
* Set the value of a nil native type
*
*/
public function __construct()
{
$this->_type = self::XMLRPC_TYPE_NIL;
$this->_value = null;
}
/**
* Return the value of this object, convert the XML-RPC native nill value into a PHP NULL
*
* @return null
*/
public function getValue()
{
return null;
}
}

View file

@ -0,0 +1,55 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Scalar.php 20208 2010-01-11 22:37:37Z lars $
*/
/**
* Zend_XmlRpc_Value
*/
require_once 'Zend/XmlRpc/Value.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_XmlRpc_Value_Scalar extends Zend_XmlRpc_Value
{
/**
* Generate the XML code that represent a scalar native MXL-RPC value
*
* @return void
*/
protected function _generateXml()
{
$generator = $this->getGenerator();
$generator->openElement('value')
->openElement($this->_type, $this->_value)
->closeElement($this->_type)
->closeElement('value');
$this->_xml = (string)$generator;
}
}

View file

@ -0,0 +1,60 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: String.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Zend_XmlRpc_Value_Scalar
*/
require_once 'Zend/XmlRpc/Value/Scalar.php';
/**
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Value_String extends Zend_XmlRpc_Value_Scalar
{
/**
* Set the value of a string native type
*
* @param string $value
*/
public function __construct($value)
{
$this->_type = self::XMLRPC_TYPE_STRING;
// Make sure this value is string and all XML characters are encoded
$this->_value = (string)$value;
}
/**
* Return the value of this object, convert the XML-RPC native string value into a PHP string
*
* @return string
*/
public function getValue()
{
return (string)$this->_value;
}
}

View file

@ -0,0 +1,76 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Struct.php 20208 2010-01-11 22:37:37Z lars $
*/
/**
* Zend_XmlRpc_Value_Collection
*/
require_once 'Zend/XmlRpc/Value/Collection.php';
/**
* @category Zend
* @package Zend_XmlRpc
* @subpackage Value
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_XmlRpc_Value_Struct extends Zend_XmlRpc_Value_Collection
{
/**
* Set the value of an struct native type
*
* @param array $value
*/
public function __construct($value)
{
$this->_type = self::XMLRPC_TYPE_STRUCT;
parent::__construct($value);
}
/**
* Generate the XML code that represent struct native MXL-RPC value
*
* @return void
*/
protected function _generateXML()
{
$generator = $this->getGenerator();
$generator->openElement('value')
->openElement('struct');
if (is_array($this->_value)) {
foreach ($this->_value as $name => $val) {
/* @var $val Zend_XmlRpc_Value */
$generator->openElement('member')
->openElement('name', $name)
->closeElement('name');
$val->generateXml();
$generator->closeElement('member');
}
}
$generator->closeElement('struct')
->closeElement('value');
$this->_xml = (string)$generator;
}
}