1 | <?php |
||
33 | final class AframeDOMDocument extends DOMImplementation |
||
34 | { |
||
35 | |||
36 | const DEFAULT_METATAGS = array( |
||
37 | array( |
||
38 | 'charset' => 'utf-8' |
||
39 | ), |
||
40 | array( |
||
41 | 'name' => 'viewport', |
||
42 | 'content' => 'width=device-width,initial-scale=1,maximum-scale=1,shrink-to-fit=no,user-scalable=no,minimal-ui' |
||
43 | ), |
||
44 | array( |
||
45 | 'name' => 'mobile-web-app-capable', |
||
46 | 'content' => 'yes' |
||
47 | ), |
||
48 | array( |
||
49 | 'name' => 'theme-color', |
||
50 | 'content' => 'black' |
||
51 | ) |
||
52 | ); |
||
53 | |||
54 | /** |
||
55 | * A-Frame DOM Document type |
||
56 | * |
||
57 | * @var \DOMDocumentType |
||
58 | */ |
||
59 | protected $doctypeObj; |
||
60 | |||
61 | /** |
||
62 | * A-Frame DOM Document |
||
63 | * |
||
64 | * @var \DOMDocument |
||
65 | */ |
||
66 | protected $docObj; |
||
67 | |||
68 | /** |
||
69 | * Scene meta tile |
||
70 | * |
||
71 | * @var string $scene_title |
||
72 | */ |
||
73 | protected $scene_title = 'Untitled'; |
||
74 | |||
75 | /** |
||
76 | * Scene meta description |
||
77 | * |
||
78 | * @var string $scene_description |
||
79 | */ |
||
80 | protected $scene_description = ''; |
||
81 | |||
82 | /** |
||
83 | * CDN Of aframe.js |
||
84 | * |
||
85 | * @var string |
||
86 | */ |
||
87 | protected $aframe_cdn; |
||
88 | |||
89 | /** |
||
90 | * Whether to use CDN |
||
91 | * |
||
92 | * @var bool $use_cdn |
||
93 | */ |
||
94 | protected $use_cdn = false; |
||
95 | |||
96 | /** |
||
97 | * <head> |
||
98 | * |
||
99 | * @var \DOMElement |
||
100 | */ |
||
101 | protected $head; |
||
102 | |||
103 | /** |
||
104 | * <body> |
||
105 | * |
||
106 | * @var \DOMElement |
||
107 | */ |
||
108 | protected $body; |
||
109 | |||
110 | /** |
||
111 | * <a-scene> |
||
112 | * |
||
113 | * @var \DOMElement |
||
114 | */ |
||
115 | protected $scene; |
||
116 | |||
117 | /** |
||
118 | * <a-assets> |
||
119 | * |
||
120 | * @var \DOMElement |
||
121 | */ |
||
122 | protected $assets; |
||
123 | |||
124 | /** |
||
125 | * Nicely formats output with indentation and extra space. |
||
126 | * |
||
127 | * @var bool |
||
128 | */ |
||
129 | protected $formatOutput = false; |
||
130 | |||
131 | /** |
||
132 | * A-Frame DOM |
||
133 | * |
||
134 | * @param Config $config |
||
135 | */ |
||
136 | 70 | public function __construct(Config $config) |
|
157 | |||
158 | /** |
||
159 | * Set CDN for aframe.js or min.js |
||
160 | * |
||
161 | * @param string $cdn |
||
162 | * @return void |
||
163 | */ |
||
164 | 70 | public function setCDN(string $cdn) |
|
168 | |||
169 | /** |
||
170 | * Render scene this DOM Object is attached to |
||
171 | * |
||
172 | * @return string |
||
173 | */ |
||
174 | 5 | public function render(): string |
|
188 | |||
189 | /** |
||
190 | * Set Scene meta title |
||
191 | * |
||
192 | * @param string $title |
||
193 | */ |
||
194 | 7 | public function setTitle(string $title) |
|
198 | |||
199 | /** |
||
200 | * Set Scene meta description |
||
201 | * |
||
202 | * @param string $description |
||
203 | */ |
||
204 | 7 | public function setDescription(string $description) |
|
208 | |||
209 | /** |
||
210 | * Append entities |
||
211 | * |
||
212 | * @param array $entities |
||
213 | * @return void |
||
214 | */ |
||
215 | 7 | public function appendEntities(array $entities) |
|
223 | |||
224 | /** |
||
225 | * Append assets |
||
226 | * |
||
227 | * @param array $assets |
||
228 | * @return void |
||
229 | */ |
||
230 | 2 | public function appendAssets(array $assets) |
|
243 | |||
244 | /** |
||
245 | * Append asset |
||
246 | * |
||
247 | * Create asset DOMElement |
||
248 | * |
||
249 | * @param AssetsInterface $asset |
||
250 | */ |
||
251 | 2 | public function appendAsset(AssetsInterface $asset) |
|
256 | |||
257 | /** |
||
258 | * Create entity DOMElement |
||
259 | * |
||
260 | * Created entity and append it to scene |
||
261 | * |
||
262 | * @param Entity $entity |
||
263 | * @return void |
||
264 | */ |
||
265 | 2 | public function appendEntity(Entity $entity) |
|
270 | |||
271 | /** |
||
272 | * Get HTML of Scene only |
||
273 | * |
||
274 | * @return string |
||
275 | */ |
||
276 | 3 | public function renderSceneOnly() |
|
284 | |||
285 | /** |
||
286 | * Add document comment for formatting |
||
287 | * |
||
288 | * @param string $element |
||
289 | * @param string $comment |
||
290 | */ |
||
291 | 4 | protected function appendFormatComment(string $element, string $comment) |
|
298 | |||
299 | /** |
||
300 | * Correct html format for tags which are not supported by DOMDocument |
||
301 | * |
||
302 | * @param string $html |
||
303 | * @return string |
||
304 | */ |
||
305 | 4 | protected function correctOutputFormat($html) |
|
323 | |||
324 | /** |
||
325 | * Prepeare head |
||
326 | * |
||
327 | * @return void |
||
328 | */ |
||
329 | 5 | protected function renderHead() |
|
336 | |||
337 | /** |
||
338 | * Append deffault metatags |
||
339 | * |
||
340 | * @return void |
||
341 | */ |
||
342 | 5 | protected function appendDefaultMetaTags() |
|
351 | |||
352 | /** |
||
353 | * Get default meta tags |
||
354 | * |
||
355 | * @return array |
||
356 | */ |
||
357 | 5 | protected function getDefaultMetaTags(): array |
|
361 | |||
362 | /** |
||
363 | * If requested by user use aframe CDN |
||
364 | * |
||
365 | * @return void |
||
366 | */ |
||
367 | 5 | protected function appendCDN() |
|
375 | |||
376 | /** |
||
377 | * Prepare body |
||
378 | * |
||
379 | * @return void |
||
380 | */ |
||
381 | 5 | protected function renderBody() |
|
385 | |||
386 | /** |
||
387 | * Create meta tags |
||
388 | * |
||
389 | * @param array $attr |
||
390 | */ |
||
391 | 5 | protected function appendMetaTag(array $attr) |
|
398 | |||
399 | /** |
||
400 | * Creates an empty DOMDocumentType object |
||
401 | * |
||
402 | * @param string $doctype |
||
403 | * @return void |
||
404 | */ |
||
405 | 70 | protected function createDocType(string $doctype) |
|
409 | |||
410 | /** |
||
411 | * Creates a DOMDocument object of the specified type with its document element |
||
412 | * |
||
413 | * @return void |
||
414 | */ |
||
415 | 70 | protected function createAframeDocument() |
|
419 | } |
||
420 |