Merge branch '2429' into 0.9.x

This commit is contained in:
James Walker 2010-08-02 16:45:23 -04:00
commit 5fa19a0384
2 changed files with 40 additions and 74 deletions

View File

@ -97,24 +97,18 @@ class MagicEnvelope
} }
public function toXML($env) { public function toXML($env) {
$dom = new DOMDocument(); $xs = new XMLStringer();
$xs->startXML();
$envelope = $dom->createElementNS(MagicEnvelope::NS, 'me:env'); $xs->elementStart('me:env', array('xmlns:me' => MagicEnvelope::NS));
$envelope->setAttribute('xmlns:me', MagicEnvelope::NS); $xs->element('me:data', array('type' => $env['data_type']), $env['data']);
$data = $dom->createElementNS(MagicEnvelope::NS, 'me:data', $env['data']); $xs->element('me:encoding', null, $env['encoding']);
$data->setAttribute('type', $env['data_type']); $xs->element('me:alg', null, $env['alg']);
$envelope->appendChild($data); $xs->element('me:sig', null, $env['sig']);
$enc = $dom->createElementNS(MagicEnvelope::NS, 'me:encoding', $env['encoding']); $xs->elementEnd('me:env');
$envelope->appendChild($enc);
$alg = $dom->createElementNS(MagicEnvelope::NS, 'me:alg', $env['alg']);
$envelope->appendChild($alg);
$sig = $dom->createElementNS(MagicEnvelope::NS, 'me:sig', $env['sig']);
$envelope->appendChild($sig);
$dom->appendChild($envelope);
$string = $xs->getString();
return $dom->saveXML(); common_debug($string);
return $string;
} }

View File

@ -106,44 +106,43 @@ class XRD
public function toXML() public function toXML()
{ {
$dom = new DOMDocument('1.0', 'UTF-8'); $xs = new XMLStringer();
$dom->formatOutput = true;
$xs->startXML();
$xrd_dom = $dom->createElementNS(XRD::XRD_NS, 'XRD'); $xs->elementStart('XRD', array('xmlns' => XRD::XRD_NS));
$dom->appendChild($xrd_dom);
if ($this->host) { if ($this->host) {
$host_dom = $dom->createElement('hm:Host', $this->host); $xs->element('hm:Host', array('xmlns:hm' => XRD::HOST_META_NS), $this->host);
$xrd_dom->setAttributeNS(XRD::XML_NS, 'xmlns:hm', XRD::HOST_META_NS);
$xrd_dom->appendChild($host_dom);
} }
if ($this->expires) { if ($this->expires) {
$expires_dom = $dom->createElement('Expires', $this->expires); $xs->element('Expires', null, $this->expires);
$xrd_dom->appendChild($expires_dom); }
}
if ($this->subject) { if ($this->subject) {
$subject_dom = $dom->createElement('Subject', $this->subject); $xs->element('Subject', null, $this->subject);
$xrd_dom->appendChild($subject_dom); }
}
foreach ($this->alias as $alias) { foreach ($this->alias as $alias) {
$alias_dom = $dom->createElement('Alias', $alias); $xs->element('Alias', null, $alias);
$xrd_dom->appendChild($alias_dom); }
}
foreach ($this->types as $type) { foreach ($this->links as $link) {
$type_dom = $dom->createElement('Type', $type); $titles = array();
$xrd_dom->appendChild($type_dom); if (isset($link['title'])) {
} $titles = $link['title'];
unset($link['title']);
}
$xs->elementStart('Link', $link);
foreach ($titles as $title) {
$xs->element('Title', null, $title);
}
$xs->elementEnd('Link');
}
$xs->elementEnd('XRD');
foreach ($this->links as $link) { return $xs->getString();
$link_dom = $this->saveLink($dom, $link);
$xrd_dom->appendChild($link_dom);
}
return $dom->saveXML();
} }
function parseType($element) function parseType($element)
@ -169,32 +168,5 @@ class XRD
return $link; return $link;
} }
function saveLink($doc, $link)
{
$link_element = $doc->createElement('Link');
if (!empty($link['rel'])) {
$link_element->setAttribute('rel', $link['rel']);
}
if (!empty($link['type'])) {
$link_element->setAttribute('type', $link['type']);
}
if (!empty($link['href'])) {
$link_element->setAttribute('href', $link['href']);
}
if (!empty($link['template'])) {
$link_element->setAttribute('template', $link['template']);
}
if (!empty($link['title']) && is_array($link['title'])) {
foreach($link['title'] as $title) {
$title = $doc->createElement('Title', $title);
$link_element->appendChild($title);
}
}
return $link_element;
}
} }