コード例 #1
0
ファイル: xrd.php プロジェクト: stevertiqo/StatusNet
 public static function parse($xml)
 {
     $xrd = new XRD();
     $dom = new DOMDocument();
     // Don't spew XML warnings to output
     $old = error_reporting();
     error_reporting($old & ~E_WARNING);
     $ok = $dom->loadXML($xml);
     error_reporting($old);
     if (!$ok) {
         // TRANS: Exception.
         throw new Exception(_m('Invalid XML.'));
     }
     $xrd_element = $dom->getElementsByTagName('XRD')->item(0);
     if (!$xrd_element) {
         // TRANS: Exception.
         throw new Exception(_m('Invalid XML, missing XRD root.'));
     }
     // Check for host-meta host
     $host = $xrd_element->getElementsByTagName('Host')->item(0);
     if ($host) {
         $xrd->host = $host->nodeValue;
     }
     // Loop through other elements
     foreach ($xrd_element->childNodes as $node) {
         if (!$node instanceof DOMElement) {
             continue;
         }
         switch ($node->tagName) {
             case 'Expires':
                 $xrd->expires = $node->nodeValue;
                 break;
             case 'Subject':
                 $xrd->subject = $node->nodeValue;
                 break;
             case 'Alias':
                 $xrd->alias[] = $node->nodeValue;
                 break;
             case 'Link':
                 $xrd->links[] = $xrd->parseLink($node);
                 break;
             case 'Type':
                 $xrd->types[] = $xrd->parseType($node);
                 break;
         }
     }
     return $xrd;
 }