import v1.1.0_RC2 | 2009-09-20
This commit is contained in:
@ -15,44 +15,11 @@
|
||||
* @category Zend
|
||||
* @package Zend_XmlRpc
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Value.php 13223 2008-12-14 11:21:31Z thomas $
|
||||
* @version $Id: Value.php 17786 2009-08-23 22:26:33Z lars $
|
||||
*/
|
||||
|
||||
/** Zend_XmlRpc_Value_Scalar */
|
||||
require_once 'Zend/XmlRpc/Value/Scalar.php';
|
||||
|
||||
/** Zend_XmlRpc_Value_Base64 */
|
||||
require_once 'Zend/XmlRpc/Value/Base64.php';
|
||||
|
||||
/** Zend_XmlRpc_Value_Boolean */
|
||||
require_once 'Zend/XmlRpc/Value/Boolean.php';
|
||||
|
||||
/** Zend_XmlRpc_Value_DateTime */
|
||||
require_once 'Zend/XmlRpc/Value/DateTime.php';
|
||||
|
||||
/** Zend_XmlRpc_Value_Double */
|
||||
require_once 'Zend/XmlRpc/Value/Double.php';
|
||||
|
||||
/** Zend_XmlRpc_Value_Integer */
|
||||
require_once 'Zend/XmlRpc/Value/Integer.php';
|
||||
|
||||
/** Zend_XmlRpc_Value_String */
|
||||
require_once 'Zend/XmlRpc/Value/String.php';
|
||||
|
||||
/** Zend_XmlRpc_Value_Nil */
|
||||
require_once 'Zend/XmlRpc/Value/Nil.php';
|
||||
|
||||
/** Zend_XmlRpc_Value_Collection */
|
||||
require_once 'Zend/XmlRpc/Value/Collection.php';
|
||||
|
||||
/** Zend_XmlRpc_Value_Array */
|
||||
require_once 'Zend/XmlRpc/Value/Array.php';
|
||||
|
||||
/** Zend_XmlRpc_Value_Struct */
|
||||
require_once 'Zend/XmlRpc/Value/Struct.php';
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@ -64,7 +31,7 @@ require_once 'Zend/XmlRpc/Value/Struct.php';
|
||||
* from PHP variables, XML string or by specifing the exact XML-RPC natvie type
|
||||
*
|
||||
* @package Zend_XmlRpc
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_XmlRpc_Value
|
||||
@ -250,31 +217,38 @@ abstract class Zend_XmlRpc_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);
|
||||
}
|
||||
}
|
||||
@ -283,17 +257,17 @@ abstract class Zend_XmlRpc_Value
|
||||
/**
|
||||
* Transform an XML string into a XML-RPC native value
|
||||
*
|
||||
* @param string|SimpleXMLElement $simple_xml A SimpleXMLElement object represent the XML string
|
||||
* @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
|
||||
*/
|
||||
private static function _xmlStringToNativeXmlRpc($simple_xml)
|
||||
private static function _xmlStringToNativeXmlRpc($xml)
|
||||
{
|
||||
if (!$simple_xml instanceof SimpleXMLElement) {
|
||||
if (!$xml instanceof SimpleXMLElement) {
|
||||
try {
|
||||
$simple_xml = @new SimpleXMLElement($simple_xml);
|
||||
$xml = @new SimpleXMLElement($xml);
|
||||
} catch (Exception $e) {
|
||||
// The given string is not a valid XML
|
||||
require_once 'Zend/XmlRpc/Value/Exception.php';
|
||||
@ -302,7 +276,7 @@ abstract class Zend_XmlRpc_Value
|
||||
}
|
||||
|
||||
// Get the key (tag name) and value from the simple xml object and convert the value to an XML-RPC native value
|
||||
list($type, $value) = each($simple_xml);
|
||||
list($type, $value) = each($xml);
|
||||
if (!$type) { // If no type was specified, the default is string
|
||||
$type = self::XMLRPC_TYPE_STRING;
|
||||
}
|
||||
@ -312,33 +286,33 @@ abstract class Zend_XmlRpc_Value
|
||||
case self::XMLRPC_TYPE_I4:
|
||||
// Fall through to the next case
|
||||
case self::XMLRPC_TYPE_INTEGER:
|
||||
require_once 'Zend/XmlRpc/Value/Integer.php';
|
||||
$xmlrpc_val = new Zend_XmlRpc_Value_Integer($value);
|
||||
break;
|
||||
case self::XMLRPC_TYPE_DOUBLE:
|
||||
require_once 'Zend/XmlRpc/Value/Double.php';
|
||||
$xmlrpc_val = new Zend_XmlRpc_Value_Double($value);
|
||||
break;
|
||||
case self::XMLRPC_TYPE_BOOLEAN:
|
||||
require_once 'Zend/XmlRpc/Value/Boolean.php';
|
||||
$xmlrpc_val = new Zend_XmlRpc_Value_Boolean($value);
|
||||
break;
|
||||
case self::XMLRPC_TYPE_STRING:
|
||||
require_once 'Zend/XmlRpc/Value/String.php';
|
||||
$xmlrpc_val = 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';
|
||||
$xmlrpc_val = 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';
|
||||
$xmlrpc_val = new Zend_XmlRpc_Value_Base64($value ,true);
|
||||
break;
|
||||
case self::XMLRPC_TYPE_NIL: // The value should always be NULL
|
||||
$xmlrpc_val = new Zend_XmlRpc_Value_Nil();
|
||||
break;
|
||||
case self::XMLRPC_TYPE_ARRAY:
|
||||
// If the XML is valid, $value must be an SimpleXML element and contain the <data> tag
|
||||
if (!$value instanceof SimpleXMLElement) {
|
||||
require_once 'Zend/XmlRpc/Value/Exception.php';
|
||||
throw new Zend_XmlRpc_Value_Exception('XML string is invalid for XML-RPC native '. self::XMLRPC_TYPE_ARRAY .' type');
|
||||
}
|
||||
|
||||
// PHP 5.2.4 introduced a regression in how empty($xml->value)
|
||||
// returns; need to look for the item specifically
|
||||
$data = null;
|
||||
@ -359,26 +333,23 @@ abstract class Zend_XmlRpc_Value
|
||||
foreach ($data->value as $element) {
|
||||
$values[] = self::_xmlStringToNativeXmlRpc($element);
|
||||
}
|
||||
require_once 'Zend/XmlRpc/Value/Array.php';
|
||||
$xmlrpc_val = new Zend_XmlRpc_Value_Array($values);
|
||||
break;
|
||||
case self::XMLRPC_TYPE_STRUCT:
|
||||
// If the XML is valid, $value must be an SimpleXML
|
||||
if ((!$value instanceof SimpleXMLElement)) {
|
||||
require_once 'Zend/XmlRpc/Value/Exception.php';
|
||||
throw new Zend_XmlRpc_Value_Exception('XML string is invalid for XML-RPC native '. self::XMLRPC_TYPE_STRUCT .' type');
|
||||
}
|
||||
$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 ((!$member->value instanceof SimpleXMLElement)) {
|
||||
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';
|
||||
$xmlrpc_val = new Zend_XmlRpc_Value_Struct($values);
|
||||
break;
|
||||
default:
|
||||
@ -386,7 +357,7 @@ abstract class Zend_XmlRpc_Value
|
||||
throw new Zend_XmlRpc_Value_Exception('Value type \''. $type .'\' parsed from the XML string is not a known XML-RPC native type');
|
||||
break;
|
||||
}
|
||||
$xmlrpc_val->_setXML($simple_xml->asXML());
|
||||
$xmlrpc_val->_setXML($xml->asXML());
|
||||
|
||||
return $xmlrpc_val;
|
||||
}
|
||||
@ -397,6 +368,26 @@ abstract class Zend_XmlRpc_Value
|
||||
$this->_as_xml = $xml;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make sure a string will be safe for XML, convert risky characters to entities
|
||||
*
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
protected function _escapeXmlEntities($str)
|
||||
{
|
||||
return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert XML entities into string values
|
||||
*
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
protected function _decodeXmlEntities($str)
|
||||
{
|
||||
return html_entity_decode($str, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user