Use outputTo() instead of asString() for including sub-elements

This commit is contained in:
Evan Prodromou 2010-12-27 09:46:25 -08:00
parent 1188d5bab2
commit f5128015be
6 changed files with 44 additions and 27 deletions

View File

@ -440,7 +440,7 @@ class Activity
} }
foreach ($this->categories as $cat) { foreach ($this->categories as $cat) {
$xs->raw($cat->asString()); $cat->outputTo($xs);
} }
// can be either URLs or enclosure objects // can be either URLs or enclosure objects

View File

@ -570,7 +570,7 @@ class ActivityObject
} }
if (!empty($this->poco)) { if (!empty($this->poco)) {
$xo->raw($this->poco->asString()); $this->poco->outputTo($xo);
} }
foreach ($this->extra as $el) { foreach ($this->extra as $el) {

View File

@ -59,6 +59,13 @@ class AtomCategory
} }
function asString() function asString()
{
$xs = new XMLStringer();
$this->outputTo($xs);
return $xs->getString();
}
function outputTo($xo)
{ {
$attribs = array(); $attribs = array();
if ($this->term !== null) { if ($this->term !== null) {
@ -70,8 +77,6 @@ class AtomCategory
if ($this->label !== null) { if ($this->label !== null) {
$attribs['label'] = $this->label; $attribs['label'] = $this->label;
} }
$xs = new XMLStringer(); $xo->element('category', $attribs);
$xs->element('category', $attribs);
return $xs->getString();
} }
} }

View File

@ -211,30 +211,34 @@ class PoCo
function asString() function asString()
{ {
$xs = new XMLStringer(true); $xs = new XMLStringer(true);
$xs->element( $this->outputTo($xs);
return $xs->getString();
}
function outputTo($xo)
{
$xo->element(
'poco:preferredUsername', 'poco:preferredUsername',
null, null,
$this->preferredUsername $this->preferredUsername
); );
$xs->element( $xo->element(
'poco:displayName', 'poco:displayName',
null, null,
$this->displayName $this->displayName
); );
if (!empty($this->note)) { if (!empty($this->note)) {
$xs->element('poco:note', null, common_xml_safe_str($this->note)); $xo->element('poco:note', null, common_xml_safe_str($this->note));
} }
if (!empty($this->address)) { if (!empty($this->address)) {
$xs->raw($this->address->asString()); $this->address->outputTo($xo);
} }
foreach ($this->urls as $url) { foreach ($this->urls as $url) {
$xs->raw($url->asString()); $url->outputTo($xo);
} }
return $xs->getString();
} }
} }

View File

@ -43,14 +43,17 @@ class PoCoAddress
function asString() function asString()
{ {
if (!empty($this->formatted)) { $xs = new XMLStringer(true);
$xs = new XMLStringer(true); $this->outputTo($xs);
$xs->elementStart('poco:address'); return $xs->getString();
$xs->element('poco:formatted', null, common_xml_safe_str($this->formatted)); }
$xs->elementEnd('poco:address');
return $xs->getString();
}
return null; function outputTo($xo)
{
if (!empty($this->formatted)) {
$xo->elementStart('poco:address');
$xo->element('poco:formatted', null, common_xml_safe_str($this->formatted));
$xo->elementEnd('poco:address');
}
} }
} }

View File

@ -53,13 +53,18 @@ class PoCoURL
function asString() function asString()
{ {
$xs = new XMLStringer(true); $xs = new XMLStringer(true);
$xs->elementStart('poco:urls'); $this->outputTo($xs);
$xs->element('poco:type', null, $this->type);
$xs->element('poco:value', null, $this->value);
if (!empty($this->primary)) {
$xs->element('poco:primary', null, 'true');
}
$xs->elementEnd('poco:urls');
return $xs->getString(); return $xs->getString();
} }
function outputTo($xo)
{
$xo->elementStart('poco:urls');
$xo->element('poco:type', null, $this->type);
$xo->element('poco:value', null, $this->value);
if (!empty($this->primary)) {
$xo->element('poco:primary', null, 'true');
}
$xo->elementEnd('poco:urls');
}
} }