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

toXML() public method

Convert this Logo to XML.
public toXML ( DOMElement $parent ) : DOMElement
$parent DOMElement The element we should append this Logo to.
return DOMElement
    public function toXML(\DOMElement $parent)
    {
        assert('is_int($this->width)');
        assert('is_int($this->height)');
        assert('is_string($this->url)');
        $doc = $parent->ownerDocument;
        $e = $doc->createElementNS(UIInfo::NS, 'mdui:Logo');
        $e->appendChild($doc->createTextNode($this->url));
        $e->setAttribute('width', (int) $this->width);
        $e->setAttribute('height', (int) $this->height);
        if (isset($this->lang)) {
            $e->setAttribute('xml:lang', $this->lang);
        }
        $parent->appendChild($e);
        return $e;
    }

Usage Example

Example #1
0
 /**
  * Test creating a basic Logo element.
  */
 public function testMarshalling()
 {
     $logo = new Logo();
     $logo->lang = "nl";
     $logo->width = 300;
     $logo->height = 200;
     $logo->url = "https://static.example.org/images/logos/logo300x200.png";
     $document = DOMDocumentFactory::fromString('<root />');
     $xml = $logo->toXML($document->firstChild);
     $logoElements = Utils::xpQuery($xml, '/root/*[local-name()=\'Logo\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:ui\']');
     $this->assertCount(1, $logoElements);
     $logoElement = $logoElements[0];
     $this->assertEquals("https://static.example.org/images/logos/logo300x200.png", $logoElement->textContent);
     $this->assertEquals("nl", $logoElement->getAttribute("xml:lang"));
     $this->assertEquals(300, $logoElement->getAttribute("width"));
     $this->assertEquals(200, $logoElement->getAttribute("height"));
 }