setDoctype($this->defaultDoctype); } $this->registry = static::$registeredDoctypes; } /** * Set or retrieve doctype * * @param string $doctype * @throws Exception\DomainException * @return Doctype */ public function __invoke($doctype = null) { if (null !== $doctype) { switch ($doctype) { case self::XHTML11: case self::XHTML1_STRICT: case self::XHTML1_TRANSITIONAL: case self::XHTML1_FRAMESET: case self::XHTML_BASIC1: case self::XHTML1_RDFA: case self::XHTML1_RDFA11: case self::XHTML5: case self::HTML4_STRICT: case self::HTML4_LOOSE: case self::HTML4_FRAMESET: case self::HTML5: $this->setDoctype($doctype); break; default: if (0 !== strpos($doctype, 'setDoctype($type); $this->registry['doctypes'][$type] = $doctype; break; } } return $this; } /** * String representation of doctype * * @return string */ public function __toString() { $doctypes = $this->getDoctypes(); return $doctypes[$this->getDoctype()]; } /** * Register the default doctypes we understand * * @return void */ protected static function registerDefaultDoctypes() { // @codingStandardsIgnoreStart static::$registeredDoctypes = new ArrayObject([ 'doctypes' => [ self::XHTML11 => '', self::XHTML1_STRICT => '', self::XHTML1_TRANSITIONAL => '', self::XHTML1_FRAMESET => '', self::XHTML1_RDFA => '', self::XHTML1_RDFA11 => '', self::XHTML_BASIC1 => '', self::XHTML5 => '', self::HTML4_STRICT => '', self::HTML4_LOOSE => '', self::HTML4_FRAMESET => '', self::HTML5 => '', ], ]); // @codingStandardsIgnoreEnd } /** * Unset the static doctype registry * * Mainly useful for testing purposes. Sets {@link $registeredDoctypes} to * a null value. * * @return void */ public static function unsetDoctypeRegistry() { static::$registeredDoctypes = null; } /** * Set doctype * * @param string $doctype * @return Doctype */ public function setDoctype($doctype) { $this->registry['doctype'] = $doctype; return $this; } /** * Retrieve doctype * * @return string */ public function getDoctype() { if (! isset($this->registry['doctype'])) { $this->setDoctype($this->defaultDoctype); } return $this->registry['doctype']; } /** * Get doctype => string mappings * * @return array */ public function getDoctypes() { return $this->registry['doctypes']; } /** * Is doctype XHTML? * * @return bool */ public function isXhtml() { return (bool) stristr($this->getDoctype(), 'xhtml'); } /** * Is doctype HTML5? (HeadMeta uses this for validation) * * @return bool */ public function isHtml5() { return (bool) stristr($this->__invoke(), ''); } /** * Is doctype RDFa? * * @return bool */ public function isRdfa() { return ($this->isHtml5() || stristr($this->getDoctype(), 'rdfa')); } }