BlogGalleryContact

Zend Framework Rest Server

silly, but the zend rest server does not serialize nested arrays ... so i came up with a little fix (for the .7.0 incubator):

--- library/Zend/Rest/Server.php 2007-03-07 11:18:03 UTC (rev 39)
+++ library/Zend/Rest/Server.php 2007-03-07 12:23:40 UTC (rev 40)
@@ -199,7 +199,7 @@
}

$method = $function->getName();
-
+
if ($class) {
$xml = "<$class generator='zend' version='1.0'>";
$xml .= "<$method>";
@@ -222,7 +222,15 @@
if (ctype_digit((string) $key)) {
$key = 'key_' . $key;
}
- $xml .= "<$key>$value</$key>";
+ if (is_array($value))
+ {
+ $xml .= "<$key>" . $this->_to_xml($value). "</$key>";
+ }
+ else
+ {
+ $xml .= "<$key>$value</$key>";
+ }
+
}

if (!$has_status) {
@@ -236,6 +244,21 @@
return $xml;
}

+
+ function _to_xml($data)
+ {
+ $xml = '';
+ foreach ($data as $key => $value) {
+ if (is_array($value))
+ {
+ $xml .= _to_xml($value);
+ continue;
+ }
+ $xml .= '<' . $key . '>' . $value . '</' . $key . '>';
+ }
+ return $xml;
+ }
+
/**
* Handle a single value
*
Related Entries:
Zend Framework Rest Server II - Return of the Characters
PHP Unit Test Systems at GSOC
beating dead smarty horses
doxygen for eclipse
everthing new
 Permalink

Comments

No new comments allowed (anymore) on this post.