Index: library/Zend/XmlRpc/Server.php =================================================================== --- library/Zend/XmlRpc/Server.php (revision 8704) +++ library/Zend/XmlRpc/Server.php (working copy) @@ -168,7 +168,8 @@ 'time' => 'dateTime.iso8601', 'array' => 'array', 'struct' => 'struct', - 'null' => 'void', + 'null' => 'nil', + 'nil' => 'nil', 'void' => 'void', 'mixed' => 'struct' ); Index: library/Zend/XmlRpc/Value.php =================================================================== --- library/Zend/XmlRpc/Value.php (revision 8704) +++ library/Zend/XmlRpc/Value.php (working copy) @@ -43,6 +43,9 @@ /** 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'; @@ -115,6 +118,7 @@ const XMLRPC_TYPE_BASE64 = 'base64'; const XMLRPC_TYPE_ARRAY = 'array'; const XMLRPC_TYPE_STRUCT = 'struct'; + const XMLRPC_TYPE_NIL = 'nil'; /** @@ -208,6 +212,9 @@ case self::XMLRPC_TYPE_BASE64: return new Zend_XmlRpc_Value_Base64($value); + case self::XMLRPC_TYPE_NIL: + return new Zend_XmlRpc_Value_Nil(); + case self::XMLRPC_TYPE_DATETIME: return new Zend_XmlRpc_Value_DateTime($value); @@ -262,6 +269,10 @@ case 'boolean': return new Zend_XmlRpc_Value_Boolean($value); + case 'NULL': + case 'null': + return new Zend_XmlRpc_Value_Nil(); + case 'string': // Fall through to the next case default: @@ -319,6 +330,9 @@ case self::XMLRPC_TYPE_BASE64: // The value should already be base64 encoded $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 tag if (!$value instanceof SimpleXMLElement) { Index: library/Zend/XmlRpc/Value/Nil.php =================================================================== --- library/Zend/XmlRpc/Value/Nil.php (revision 0) +++ library/Zend/XmlRpc/Value/Nil.php (revision 0) @@ -0,0 +1,78 @@ +_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; + } + + /** + * Return the XML code representing the nil + * + * @return string + */ + public function saveXML() + { + if (! $this->_as_xml) { // The XML was not generated yet + $dom = new DOMDocument('1.0', 'UTF-8'); + $value = $dom->appendChild($dom->createElement('value')); + $type = $value->appendChild($dom->createElement($this->_type)); + + $this->_as_dom = $value; + $this->_as_xml = $this->_stripXmlDeclaration($dom); + } + + return $this->_as_xml; + } +} + Index: tests/Zend/XmlRpc/ValueTest.php =================================================================== --- tests/Zend/XmlRpc/ValueTest.php (revision 8704) +++ tests/Zend/XmlRpc/ValueTest.php (working copy) @@ -18,6 +18,7 @@ require_once 'Zend/XmlRpc/Value/Double.php'; require_once 'Zend/XmlRpc/Value/Integer.php'; require_once 'Zend/XmlRpc/Value/String.php'; +require_once 'Zend/XmlRpc/Value/Nil.php'; require_once 'Zend/XmlRpc/Value/Struct.php'; /** @@ -179,6 +180,37 @@ $this->assertEquals($this->wrapXml($xml), $val->saveXML()); } + //Nil + + public function testFactoryAutodetectsNil() + { + $val = Zend_XmlRpc_Value::getXmlRpcValue(NULL); + $this->assertXmlRpcType('nil', $val); + } + + public function testMarshalNilFromNative() + { + $native = NULL; + $val = Zend_XmlRpc_Value::getXmlRpcValue($native, + Zend_XmlRpc_Value::XMLRPC_TYPE_NIL); + + $this->assertXmlRpcType('nil', $val); + $this->assertSame($native, $val->getValue()); + } + + public function testMarshalNilFromXmlRpc() + { + $xml = ''; + $val = Zend_XmlRpc_Value::getXmlRpcValue($xml, + Zend_XmlRpc_Value::XML_STRING); + + $this->assertXmlRpcType('nil', $val); + $this->assertEquals('nil', $val->getType()); + $this->assertSame(NULL, $val->getValue()); + $this->assertType('DomElement', $val->getAsDOM()); + $this->assertEquals($this->wrapXml($xml), $val->saveXML()); + } + // Array public function testFactoryAutodetectsArray()