1 | <?php |
||
28 | class Page |
||
29 | { |
||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | private $title = ''; |
||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | private $id = ''; |
||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | private $lang = 'en'; |
||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | private $encoding = 'utf8'; |
||
46 | /** |
||
47 | * @var array<string> |
||
48 | */ |
||
49 | private $classes = []; |
||
50 | /** |
||
51 | * @var array<\Minotaur\Tags\Tag> |
||
52 | */ |
||
53 | private $metas = []; |
||
54 | /** |
||
55 | * @var array<\Minotaur\Tags\Tag> |
||
56 | */ |
||
57 | private $links = []; |
||
58 | /** |
||
59 | * @var array<\Minotaur\Tags\Tag> |
||
60 | */ |
||
61 | private $headScripts = []; |
||
62 | /** |
||
63 | * @var array<\Minotaur\Tags\Tag> |
||
64 | */ |
||
65 | private $bodyScripts = []; |
||
66 | |||
67 | /** |
||
68 | * Gets the classes for the <body> tag. |
||
69 | * |
||
70 | * @return array<string> |
||
71 | */ |
||
72 | public function getBodyClasses(): array |
||
76 | |||
77 | /** |
||
78 | * Adds CSS classes to those for the <body> tag. |
||
79 | * |
||
80 | * @param iterable<string> The CSS classes |
||
81 | */ |
||
82 | public function addBodyClasses(iterable $classes): self |
||
90 | |||
91 | /** |
||
92 | * Sets the page language. |
||
93 | * |
||
94 | * @param $lang - The new language |
||
95 | * @return self provides a fluent interface |
||
96 | */ |
||
97 | public function setLang(string $lang): self |
||
102 | |||
103 | /** |
||
104 | * Gets the page language, by default en. |
||
105 | */ |
||
106 | public function getLang(): string |
||
110 | |||
111 | /** |
||
112 | * Gets the page encoding, by default utf8. |
||
113 | */ |
||
114 | public function getEncoding(): string |
||
118 | |||
119 | /** |
||
120 | * Sets the page encoding (e.g. utf8) |
||
121 | * |
||
122 | * @param $encoding - The page encoding |
||
123 | * @return self provides a fluent interface |
||
124 | */ |
||
125 | public function setEncoding(string $encoding): self |
||
130 | |||
131 | /** |
||
132 | * Gets the page title |
||
133 | */ |
||
134 | public function getTitle(): string |
||
138 | |||
139 | /** |
||
140 | * Gets the page <meta/> tags. |
||
141 | */ |
||
142 | public function getMeta(): array |
||
146 | |||
147 | /** |
||
148 | * Gets the page <link/> tags. |
||
149 | */ |
||
150 | public function getLinks(): array |
||
154 | |||
155 | /** |
||
156 | * Gets the <script> tags in the page head. |
||
157 | * |
||
158 | * @return array<\Minotaur\Tags\Tag> |
||
159 | */ |
||
160 | public function getHeadScripts(): array |
||
164 | |||
165 | /** |
||
166 | * Gets the <script> tags in the page body. |
||
167 | * |
||
168 | * @return array<\Minotaur\Tags\Tag> |
||
169 | */ |
||
170 | public function getBodyScripts(): array |
||
174 | |||
175 | /** |
||
176 | * Sets the page title. |
||
177 | * |
||
178 | * @param $title - The new page title |
||
179 | * @return self provides a fluent interface |
||
180 | */ |
||
181 | public function setTitle(string $title): self |
||
186 | |||
187 | /** |
||
188 | * Gets the page id. |
||
189 | */ |
||
190 | public function getBodyId(): string |
||
194 | |||
195 | /** |
||
196 | * Sets the page id. |
||
197 | * |
||
198 | * @param $id - The new id |
||
199 | * @return self provides a fluent interface |
||
200 | */ |
||
201 | public function setBodyId(string $id): self |
||
206 | |||
207 | /** |
||
208 | * Adds a <meta> tag. |
||
209 | * |
||
210 | * @param $name - The tag name attribute |
||
211 | * @param $content - The tag content attribute |
||
212 | * @return self provides a fluent interface |
||
213 | */ |
||
214 | public function addMeta(string $name, string $content): self |
||
219 | |||
220 | /** |
||
221 | * Adds a stylesheet. |
||
222 | * |
||
223 | * @param $src - The file location |
||
224 | * @param $mime - Optional MIME type |
||
225 | * @param iterable<string> $media Optional list of media types |
||
226 | * @return self provides a fluent interface |
||
227 | */ |
||
228 | public function addStylesheet(string $src, string $mime = '', iterable $media = null): self |
||
240 | |||
241 | /** |
||
242 | * Adds a <link> tag. |
||
243 | * |
||
244 | * @param $rel - The relationship |
||
245 | * @param $href - The resource HREF |
||
246 | * @param $sizes - Optional sizes |
||
247 | * @param $crossorigin - Optional crossorigin |
||
248 | * @param $integrity - Optional integrity |
||
249 | * @return self provides a fluent interface |
||
250 | */ |
||
251 | public function addLink(string $rel, string $href, string $sizes = '', string $crossorigin = '', string $integrity = ''): self |
||
266 | |||
267 | /** |
||
268 | * Adds an external script to the head. |
||
269 | * |
||
270 | * @param $src - The script location |
||
271 | * @param $mime - Optional MIME type |
||
272 | * @return self provides a fluent interface |
||
273 | */ |
||
274 | public function addHeadScript(string $src, string $mime = ''): self |
||
283 | |||
284 | /** |
||
285 | * Adds an inline script to the head. |
||
286 | * |
||
287 | * @param $script - The inline JavaScript |
||
288 | * @param $mime - Optional MIME type |
||
289 | * @return self provides a fluent interface |
||
290 | */ |
||
291 | public function addHeadScriptInline(string $script, string $mime = ''): self |
||
300 | |||
301 | /** |
||
302 | * Adds an external script to the body. |
||
303 | * |
||
304 | * @param $src - The script location |
||
305 | * @param $mime - Optional MIME type |
||
306 | * @return self provides a fluent interface |
||
307 | */ |
||
308 | public function addBodyScript(string $src, string $mime = ''): self |
||
317 | |||
318 | /** |
||
319 | * Adds an inline script to the mody. |
||
320 | * |
||
321 | * @param $script - The inline JavaScript |
||
322 | * @param $mime - Optional MIME type |
||
323 | * @return self provides a fluent interface |
||
324 | */ |
||
325 | public function addBodyScriptInline(string $script, string $mime = ''): self |
||
334 | } |
||
335 |