‪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 
76  public function getXmlPrologue(): string
77  {
78  if ($this->getXhtmlVersion() === 110) {
79  return '<?xml version="1.1" encoding="utf-8"?>';
80  }
81  if ($this->getXhtmlVersion()) {
82  return '<?xml version="1.0" encoding="utf-8"?>';
83  }
84  return '';
85  }
86 
87  private function getXhtmlVersion(): ?int
88  {
89  return match ($this) {
90  self::xhtmlTransitional, self::xhtmlStrict => 100,
91  self::xhtmlBasic => 105,
92  self::xhtml11, self::xhtmlRdfa10 => 110,
93  default => null
94  };
95  }
96 
97  public function getMetaCharsetTag(): string
98  {
99  if ($this->‪isXmlCompliant()) {
100  return '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
101  }
102  if ($this === DocType::html5) {
103  // see https://www.w3.org/International/questions/qa-html-encoding-declarations.en.html
104  return '<meta charset="utf-8">';
105  }
106  return '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
107  }
108 
112  public function shouldIncludeFrameBorderAttribute(): bool
113  {
114  return $this !== self::html5;
115  }
116 
117  public static function createFromConfigurationKey(?string $key): self
118  {
119  return match ($key) {
120  // config.doctype options
121  'xhtml_trans' => self::xhtmlTransitional,
122  'xhtml_strict' => self::xhtmlStrict,
123  'xhtml_basic' => self::xhtmlBasic,
124  'xhtml_11' => self::xhtml11,
125  'xhtml+rdfa_10' => self::xhtmlRdfa10,
126  'html5' => self::html5,
127  'none' => self::none,
128  default => self::html5,
129  };
130  }
131 }
‪TYPO3\CMS\Core\Type\isXmlCompliant
‪@ isXmlCompliant
Definition: DocType.php:45
‪TYPO3\CMS\Core\Type\DocType
‪DocType
Definition: DocType.php:27
‪TYPO3\CMS\Core\Type