‪TYPO3CMS  ‪main
DocType.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 namespace ‪TYPO3\CMS\Core\Type;
19 
27 {
28  case html5;
29  // XHTML 1.0 Strict doctype
30  case xhtmlStrict;
31  // XHTML 1.1 doctype
32  case xhtml11;
33  // XHTML 1.0 Transitional doctype
34  case xhtmlTransitional;
35  // XHTML basic doctype
36  case xhtmlBasic;
37  // XHTML+RDFa 1.0 doctype
38  case xhtmlRdfa10;
39  case none;
40 
45  public function ‪isXmlCompliant(): bool
46  {
47  return match ($this) {
48  self::xhtmlRdfa10, self::xhtml11, self::xhtmlStrict, self::xhtmlBasic, self::xhtmlTransitional => true,
49  default => false,
50  };
51  }
52 
53  public function getDoctypeDeclaration(): string
54  {
55  return match ($this) {
56  self::xhtmlTransitional => '<!DOCTYPE html
57  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
58  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
59  self::xhtmlStrict => '<!DOCTYPE html
60  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
61  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
62  self::xhtmlBasic => '<!DOCTYPE html
63  PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
64  "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">',
65  self::xhtml11 => '<!DOCTYPE html
66  PUBLIC "-//W3C//DTD XHTML 1.1//EN"
67  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
68  self::xhtmlRdfa10 => '<!DOCTYPE html
69  PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
70  "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">',
71  self::html5 => '<!DOCTYPE html>',
72  default => ''
73  };
74  }
75 
79  public function getXhtmlDocType(): string
80  {
81  return match ($this) {
82  self::xhtmlTransitional => 'xhtml_trans',
83  self::xhtmlStrict => 'xhtml_strict',
84  self::xhtmlBasic => 'xhtml_basic',
85  self::xhtml11 => 'xhtml_11',
86  self::xhtmlRdfa10 => 'xhtml+rdfa_10',
87  default => ''
88  };
89  }
90  public function getXmlPrologue(): string
91  {
92  if ($this->getXhtmlVersion() === 110) {
93  return '<?xml version="1.1" encoding="utf-8"?>';
94  }
95  if ($this->getXhtmlVersion()) {
96  return '<?xml version="1.0" encoding="utf-8"?>';
97  }
98  return '';
99  }
100 
104  public function getXhtmlVersion(): ?int
105  {
106  return match ($this) {
107  self::xhtmlTransitional, self::xhtmlStrict => 100,
108  self::xhtmlBasic => 105,
109  self::xhtml11, self::xhtmlRdfa10 => 110,
110  default => null
111  };
112  }
113 
114  public function getMetaCharsetTag(): string
115  {
116  if ($this->‪isXmlCompliant()) {
117  return '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
118  }
119  if ($this === DocType::html5) {
120  // see https://www.w3.org/International/questions/qa-html-encoding-declarations.en.html
121  return '<meta charset="utf-8">';
122  }
123  return '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
124  }
125 
129  public function shouldIncludeFrameBorderAttribute(): bool
130  {
131  return $this !== self::html5;
132  }
133 
134  public static function createFromConfigurationKey(?string $key): self
135  {
136  return match ($key) {
137  // config.doctype options and config.xhtmlDoctype
138  'xhtml_trans' => self::xhtmlTransitional,
139  'xhtml_strict' => self::xhtmlStrict,
140  'xhtml_basic' => self::xhtmlBasic,
141  'xhtml_11' => self::xhtml11,
142  'xhtml+rdfa_10' => self::xhtmlRdfa10,
143  'html5' => self::html5,
144  'none' => self::none,
145  default => self::html5,
146  };
147  }
148 }
‪TYPO3\CMS\Core\Type\isXmlCompliant
‪@ isXmlCompliant
Definition: DocType.php:45
‪TYPO3\CMS\Core\Type\DocType
‪DocType
Definition: DocType.php:27
‪TYPO3\CMS\Core\Type