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 | 71 | public function __construct(Config $config) |
|
152 | |||
153 | /** |
||
154 | * Set CDN for aframe.js or min.js |
||
155 | * |
||
156 | * @param string $cdn |
||
157 | * @return void |
||
158 | */ |
||
159 | 71 | public function setCDN(string $cdn) |
|
163 | |||
164 | /** |
||
165 | * Render scene this DOM Object is attached to |
||
166 | * |
||
167 | * @return string |
||
168 | */ |
||
169 | 5 | public function render(): string |
|
183 | |||
184 | /** |
||
185 | * Set Scene meta title |
||
186 | * |
||
187 | * @param string $title |
||
188 | */ |
||
189 | 7 | public function setTitle(string $title) |
|
193 | |||
194 | /** |
||
195 | * Set Scene meta description |
||
196 | * |
||
197 | * @param string $description |
||
198 | */ |
||
199 | 7 | public function setDescription(string $description) |
|
203 | |||
204 | /** |
||
205 | * Append entities |
||
206 | * |
||
207 | * @param array $entities |
||
208 | * @return void |
||
209 | */ |
||
210 | 7 | public function appendEntities(array $entities) |
|
218 | |||
219 | /** |
||
220 | * Append assets |
||
221 | * |
||
222 | * @param array $assets |
||
223 | * @return void |
||
224 | */ |
||
225 | 2 | public function appendAssets(array $assets) |
|
238 | |||
239 | /** |
||
240 | * Append asset |
||
241 | * |
||
242 | * Create asset DOMElement |
||
243 | * |
||
244 | * @param AssetsInterface $asset |
||
245 | */ |
||
246 | 2 | public function appendAsset(AssetsInterface $asset) |
|
251 | |||
252 | /** |
||
253 | * Create entity DOMElement |
||
254 | * |
||
255 | * Created entity and append it to scene |
||
256 | * |
||
257 | * @param Entity $entity |
||
258 | * @return void |
||
259 | */ |
||
260 | 2 | public function appendEntity(Entity $entity) |
|
265 | |||
266 | /** |
||
267 | * Get HTML of Scene only |
||
268 | * |
||
269 | * @return string |
||
270 | */ |
||
271 | 3 | public function renderSceneOnly() |
|
279 | |||
280 | /** |
||
281 | * Add document comment for formatting |
||
282 | * |
||
283 | * @param string $element |
||
284 | * @param string $comment |
||
285 | */ |
||
286 | 4 | protected function appendFormatComment(string $element, string $comment) |
|
293 | |||
294 | /** |
||
295 | * Correct html format for tags which are not supported by DOMDocument |
||
296 | * |
||
297 | * @param string $html |
||
298 | * @return string |
||
299 | */ |
||
300 | 4 | protected function correctOutputFormat($html) |
|
318 | |||
319 | /** |
||
320 | * Prepeare head |
||
321 | * |
||
322 | * @return void |
||
323 | */ |
||
324 | 5 | protected function renderHead() |
|
331 | |||
332 | /** |
||
333 | * Append deffault metatags |
||
334 | * |
||
335 | * @return void |
||
336 | */ |
||
337 | 5 | protected function appendDefaultMetaTags() |
|
346 | |||
347 | /** |
||
348 | * Get default meta tags |
||
349 | * |
||
350 | * @return array |
||
351 | */ |
||
352 | 5 | protected function getDefaultMetaTags(): array |
|
356 | |||
357 | /** |
||
358 | * If requested by user use aframe CDN |
||
359 | * |
||
360 | * @return void |
||
361 | */ |
||
362 | 5 | protected function appendCDN() |
|
370 | |||
371 | /** |
||
372 | * Prepare body |
||
373 | * |
||
374 | * @return void |
||
375 | */ |
||
376 | 5 | protected function renderBody() |
|
380 | |||
381 | /** |
||
382 | * Create meta tags |
||
383 | * |
||
384 | * @param array $attr |
||
385 | */ |
||
386 | 5 | protected function appendMetaTag(array $attr) |
|
393 | |||
394 | /** |
||
395 | * Creates an empty DOMDocumentType object |
||
396 | * |
||
397 | * @param string $doctype |
||
398 | * @return void |
||
399 | */ |
||
400 | 71 | protected function createDocType(string $doctype) |
|
404 | |||
405 | /** |
||
406 | * Creates a DOMDocument object of the specified type with its document element |
||
407 | * |
||
408 | * @return void |
||
409 | */ |
||
410 | 71 | protected function createAframeDocument() |
|
414 | |||
415 | /** |
||
416 | * Create dom elements for DOMDocument |
||
417 | * |
||
418 | * @return void |
||
419 | */ |
||
420 | 71 | protected function documentBootstrap() |
|
431 | } |
||
432 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.