SAML2\XML\mdui\UIInfo::toXML PHP Method

toXML() public method

Convert this UIInfo to XML.
public toXML ( DOMElement $parent ) : DOMElement | null
$parent DOMElement The element we should append to.
return DOMElement | null
    public function toXML(\DOMElement $parent)
    {
        assert('is_array($this->DisplayName)');
        assert('is_array($this->InformationURL)');
        assert('is_array($this->PrivacyStatementURL)');
        assert('is_array($this->Keywords)');
        assert('is_array($this->Logo)');
        assert('is_array($this->children)');
        $e = null;
        if (!empty($this->DisplayName) || !empty($this->Description) || !empty($this->InformationURL) || !empty($this->PrivacyStatementURL) || !empty($this->Keywords) || !empty($this->Logo) || !empty($this->children)) {
            $doc = $parent->ownerDocument;
            $e = $doc->createElementNS(self::NS, 'mdui:UIInfo');
            $parent->appendChild($e);
            Utils::addStrings($e, self::NS, 'mdui:DisplayName', true, $this->DisplayName);
            Utils::addStrings($e, self::NS, 'mdui:Description', true, $this->Description);
            Utils::addStrings($e, self::NS, 'mdui:InformationURL', true, $this->InformationURL);
            Utils::addStrings($e, self::NS, 'mdui:PrivacyStatementURL', true, $this->PrivacyStatementURL);
            if (!empty($this->Keywords)) {
                foreach ($this->Keywords as $child) {
                    $child->toXML($e);
                }
            }
            if (!empty($this->Logo)) {
                foreach ($this->Logo as $child) {
                    $child->toXML($e);
                }
            }
            if (!empty($this->children)) {
                foreach ($this->children as $child) {
                    $child->toXML($e);
                }
            }
        }
        return $e;
    }

Usage Example

Example #1
0
 /**
  * Test creating an UIinfo element with XML children
  */
 public function testMarshallingChildren()
 {
     $keywords = new Keywords();
     $keywords->lang = "nl";
     $keywords->Keywords = array("voorbeeld", "specimen");
     $logo = new Logo();
     $logo->lang = "nl";
     $logo->width = 30;
     $logo->height = 20;
     $logo->url = "https://example.edu/logo.png";
     $discohints = new DiscoHints();
     $discohints->IPHint = array("192.168.6.0/24", "fd00:0123:aa:1001::/64");
     // keywords appears twice, direcyly under UIinfo and as child of DiscoHints
     $discohints->children = array($keywords);
     $uiinfo = new UIInfo();
     $uiinfo->Logo = array($logo);
     $uiinfo->Keywords = array($keywords);
     $uiinfo->children = array($discohints);
     $document = DOMDocumentFactory::fromString('<root />');
     $xml = $uiinfo->toXML($document->firstChild);
     $infoElements = Utils::xpQuery($xml, '/root/*[local-name()=\'UIInfo\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:ui\']');
     $this->assertCount(1, $infoElements);
     $infoElement = $infoElements[0];
     $logoElements = Utils::xpQuery($infoElement, './*[local-name()=\'Logo\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:ui\']');
     $this->assertCount(1, $logoElements);
     $this->assertEquals("https://example.edu/logo.png", $logoElements[0]->textContent);
     $keywordElements = Utils::xpQuery($infoElement, './*[local-name()=\'Keywords\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:ui\']');
     $this->assertCount(1, $keywordElements);
     $this->assertEquals("voorbeeld specimen", $keywordElements[0]->textContent);
     $this->assertEquals("nl", $keywordElements[0]->getAttribute("xml:lang"));
     $discoElements = Utils::xpQuery($infoElement, './*[local-name()=\'DiscoHints\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:ui\']');
     $this->assertCount(1, $discoElements);
     $discoElement = $discoElements[0];
     $iphintElements = Utils::xpQuery($discoElement, './*[local-name()=\'IPHint\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:ui\']');
     $this->assertCount(2, $iphintElements);
     $this->assertEquals("192.168.6.0/24", $iphintElements[0]->textContent);
     $this->assertEquals("fd00:0123:aa:1001::/64", $iphintElements[1]->textContent);
     $keywordElements = Utils::xpQuery($discoElement, './*[local-name()=\'Keywords\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:ui\']');
     $this->assertCount(1, $keywordElements);
     $this->assertEquals("voorbeeld specimen", $keywordElements[0]->textContent);
     $this->assertEquals("nl", $keywordElements[0]->getAttribute("xml:lang"));
 }