1 | <?php |
||
33 | final class AframeDOMDocument extends DOMImplementation |
||
34 | { |
||
35 | use AframeDOMProcessor; |
||
36 | |||
37 | /** |
||
38 | * A-Frame DOM Document type |
||
39 | * |
||
40 | * @var \DOMDocumentType |
||
41 | */ |
||
42 | protected $doctypeObj; |
||
43 | |||
44 | /** |
||
45 | * A-Frame DOM Document |
||
46 | * |
||
47 | * @var \DOMDocument |
||
48 | */ |
||
49 | protected $docObj; |
||
50 | |||
51 | /** |
||
52 | * Scene meta tile |
||
53 | * |
||
54 | * @var string $scene_title |
||
55 | */ |
||
56 | protected $scene_title = 'Untitled'; |
||
57 | |||
58 | /** |
||
59 | * Scene meta description |
||
60 | * |
||
61 | * @var string $scene_description |
||
62 | */ |
||
63 | protected $scene_description = ''; |
||
64 | |||
65 | /** |
||
66 | * <head> |
||
67 | * |
||
68 | * @var \DOMElement |
||
69 | */ |
||
70 | protected $head; |
||
71 | |||
72 | /** |
||
73 | * <body> |
||
74 | * |
||
75 | * @var \DOMElement |
||
76 | */ |
||
77 | protected $body; |
||
78 | |||
79 | /** |
||
80 | * <a-scene> |
||
81 | * |
||
82 | * @var \DOMElement |
||
83 | */ |
||
84 | protected $scene; |
||
85 | |||
86 | /** |
||
87 | * <a-assets> |
||
88 | * |
||
89 | * @var \DOMElement |
||
90 | */ |
||
91 | protected $assets; |
||
92 | |||
93 | /************ |
||
94 | * CONFIG |
||
95 | ***********/ |
||
96 | |||
97 | /** |
||
98 | * Nicely formats output with indentation and extra space. |
||
99 | * |
||
100 | * @var bool |
||
101 | */ |
||
102 | protected $format_output = false; |
||
103 | |||
104 | /** |
||
105 | * CDN Of aframe.js |
||
106 | * |
||
107 | * @var string |
||
108 | */ |
||
109 | protected $cdn_url; |
||
110 | |||
111 | /** |
||
112 | * Whether to use CDN |
||
113 | * |
||
114 | * @var bool $use_cdn |
||
115 | */ |
||
116 | protected $use_cdn = false; |
||
117 | |||
118 | /** |
||
119 | * aframe assets URI relative to App's base URL / domain |
||
120 | * |
||
121 | * @var string assets_uri |
||
122 | */ |
||
123 | protected $assets_uri; |
||
124 | |||
125 | /** |
||
126 | * Extra scrits to add into head |
||
127 | * |
||
128 | * Like components and shaders |
||
129 | * |
||
130 | * @var array $scripts |
||
131 | */ |
||
132 | protected $scripts = array(); |
||
133 | |||
134 | /** |
||
135 | * A-Frame DOM |
||
136 | * |
||
137 | * @param Config $config |
||
138 | */ |
||
139 | 103 | public function __construct(Config $config) |
|
153 | |||
154 | /** |
||
155 | * Render scene this DOM Object is attached to |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | 13 | public function render(): string |
|
174 | |||
175 | /** |
||
176 | * Set Scene meta title |
||
177 | * |
||
178 | * @param string $title |
||
179 | */ |
||
180 | 1 | public function setTitle(string $title) |
|
184 | |||
185 | /** |
||
186 | * Set Scene meta description |
||
187 | * |
||
188 | * @param string $description |
||
189 | */ |
||
190 | 1 | public function setDescription(string $description) |
|
194 | |||
195 | /** |
||
196 | * Append entities |
||
197 | * |
||
198 | * @param array $entities |
||
199 | * @return void |
||
200 | */ |
||
201 | 24 | public function appendEntities(array $entities) |
|
209 | |||
210 | /** |
||
211 | * Append assets |
||
212 | * |
||
213 | * @param array $assets |
||
214 | * @return void |
||
215 | */ |
||
216 | 3 | public function appendAssets(array $assets) |
|
229 | |||
230 | /** |
||
231 | * Register scripts to be added to DOM |
||
232 | * |
||
233 | * @param array $scripts |
||
234 | * @return void |
||
235 | */ |
||
236 | 2 | public function registerScripts(array $scripts) |
|
237 | { |
||
238 | 2 | $this->scripts = array_merge($this->scripts, $scripts); |
|
239 | 2 | } |
|
240 | /** |
||
241 | * Append scripts |
||
242 | * |
||
243 | * @param array $scripts |
||
244 | * @return void |
||
245 | */ |
||
246 | 13 | public function appendScripts(array $scripts) |
|
247 | { |
||
248 | 13 | foreach($scripts as $url => $use) { |
|
249 | 2 | (!$use)?:$this->appendScript($url); |
|
250 | } |
||
251 | 13 | } |
|
252 | |||
253 | /** |
||
254 | * Append script |
||
255 | * |
||
256 | * @param string $script_uri |
||
257 | * @return void |
||
258 | */ |
||
259 | 2 | public function appendScript(string $script_uri) |
|
260 | { |
||
261 | 2 | $extra_script_url = sprintf('%s%s',$this->assets_uri, $script_uri); |
|
262 | 2 | $extra_script = $this->docObj->createElement('script'); |
|
263 | 2 | $extra_script->setAttribute('src', $extra_script_url); |
|
264 | 2 | $this->head->appendChild($extra_script); |
|
265 | 2 | } |
|
266 | /** |
||
267 | * Append asset |
||
268 | * |
||
269 | * Create asset DOMElement |
||
270 | * |
||
271 | * @param AssetsInterface $asset |
||
272 | */ |
||
273 | 3 | public function appendAsset(AssetsInterface $asset) |
|
278 | |||
279 | /** |
||
280 | * Create entity DOMElement |
||
281 | * |
||
282 | * Created entity and append it to scene |
||
283 | * |
||
284 | * @param Entity $entity |
||
285 | * @return void |
||
286 | */ |
||
287 | 14 | public function appendEntity(Entity $entity) |
|
292 | |||
293 | /** |
||
294 | * Get HTML of Scene only |
||
295 | * |
||
296 | * @return string |
||
297 | */ |
||
298 | 12 | public function renderSceneOnly() |
|
307 | |||
308 | /** |
||
309 | * Add scene components |
||
310 | * |
||
311 | * @param array $components |
||
312 | * @return void |
||
313 | */ |
||
314 | 24 | public function appendSceneComponents(array $components) |
|
325 | |||
326 | /** |
||
327 | * Append DOM attributes no set by components |
||
328 | * |
||
329 | * @param \DOMElement $a_entity |
||
|
|||
330 | */ |
||
331 | 24 | public function appendSceneAttributes(array $attrs) |
|
332 | { |
||
333 | 24 | foreach ($attrs as $attr => $val) { |
|
334 | 2 | if(is_bool($val)) |
|
335 | 1 | $val = $val ? '' : 'false'; |
|
336 | 2 | $this->appendSceneAttribute($attr, $val); |
|
337 | } |
||
338 | 24 | } |
|
339 | |||
340 | 2 | private function appendSceneAttribute($attr, $val) |
|
341 | { |
||
342 | 2 | if ($attr === 'id' || is_numeric($val)) |
|
343 | 1 | return; |
|
344 | |||
345 | 2 | $this->scene->setAttribute($attr, $val); |
|
346 | 2 | } |
|
347 | |||
348 | |||
349 | /** |
||
350 | * Set configuration option related to DOM |
||
351 | * |
||
352 | * @param Config $config |
||
353 | * @return void |
||
354 | */ |
||
355 | 103 | protected function configOptions(Config $config) |
|
362 | |||
363 | /** |
||
364 | * Set individual option |
||
365 | * |
||
366 | * @param Config $config |
||
367 | * @param string $opt |
||
368 | * @param mixed $default |
||
369 | * @return void |
||
370 | */ |
||
371 | 103 | protected function setConfigurationOption(Config $config, string $opt, $default) |
|
375 | } |
||
376 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.