Pop\Dom\Dom::setDoctype PHP Method

setDoctype() public method

Method to set the document type.
public setDoctype ( string $doctype = null ) : Dom
$doctype string
return Dom
    public function setDoctype($doctype = null)
    {
        if (null !== $doctype) {
            $doctype = (int) $doctype;
            if (array_key_exists($doctype, Dom::$doctypes)) {
                $this->doctype = $doctype;
                switch ($this->doctype) {
                    case Dom::ATOM:
                        $this->contentType = 'application/atom+xml';
                        break;
                    case Dom::RSS:
                        $this->contentType = 'application/rss+xml';
                        break;
                    case Dom::XML:
                        $this->contentType = 'application/xml';
                        break;
                    default:
                        $this->contentType = 'text/html';
                }
            }
        } else {
            $this->doctype = null;
        }
        return $this;
    }

Usage Example

Beispiel #1
0
 public function testSetAndGetDoctype()
 {
     $d = new Dom(Dom::XHTML11);
     $d->setDoctype(Dom::ATOM);
     $this->assertContains('<?xml version="1.0"', $d->getDoctype());
     $d->setDoctype(Dom::RSS);
     $this->assertContains('<?xml version="1.0"', $d->getDoctype());
     $d->setDoctype(Dom::XML);
     $this->assertContains('<?xml version="1.0"', $d->getDoctype());
 }