Permalink
Browse files

Objects are now serialized to arrays so they can be passed as data as…

… well
  • Loading branch information...
1 parent 0f6f33b commit 892bb5b3b977f26eef45a387c4c8e5506372194d @jbroadway committed Apr 3, 2012
Showing with 15 additions and 0 deletions.
  1. +3 −0 ActiveResource.php
  2. +12 −0 tests/ActiveResource.php
View
3 ActiveResource.php
@@ -304,6 +304,9 @@ function _build_xml ($k, $v) {
if (! is_numeric ($k)) {
$res = '<' . $k . '{{attributes}}>';
}
+ if (is_object ($v)) {
+ $v = (array) $v;
+ }
if (is_array ($v)) {
foreach ($v as $key => $value) {
// handle attributes of repeating tags
View
12 tests/ActiveResource.php
@@ -58,6 +58,18 @@ function test_build_xml () {
// starting from a SimpleXMLElement
$xml = new SimpleXMLElement ('<foo><bar asdf="qwerty" />what</foo>');
$this->assertEquals ($t->_build_xml (0, $xml), "<foo><bar asdf=\"qwerty\"/>what</foo>\n");
+
+ // testing objects converted to arrays
+ $this->assertEquals (
+ $t->_build_xml ('foo', array ((object) array ('bar' => 'asdf'))),
+ "<foo><bar>asdf</bar>\n</foo>\n"
+ );
+
+ // testing objects converted to arrays
+ $this->assertEquals (
+ $t->_build_xml ('foo', array ((object) array ('bar' => (object) array ('asdf' => 'qwerty')))),
+ "<foo><bar><asdf>qwerty</asdf>\n</bar>\n</foo>\n"
+ );
}
function test_pleuralize () {

0 comments on commit 892bb5b

Please sign in to comment.