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 | 98 | * @var array $scripts |
|
131 | */ |
||
132 | protected $scripts = array(); |
||
133 | 98 | ||
134 | /** |
||
135 | * A-Frame DOM |
||
136 | 98 | * |
|
137 | * @param Config $config |
||
138 | */ |
||
139 | 98 | public function __construct(Config $config) |
|
140 | { |
||
141 | /* Config */ |
||
142 | 98 | $this->configOptions($config); |
|
143 | 98 | ||
144 | /* Create HTML5 Document type */ |
||
145 | $this->createDocType('html'); |
||
146 | |||
147 | /* Create A-Frame DOM Document */ |
||
148 | $this->createAframeDocument(); |
||
149 | |||
150 | 8 | /* Create boostrap elements */ |
|
151 | $this->documentBootstrap(); |
||
152 | 8 | } |
|
153 | |||
154 | 8 | /** |
|
155 | 8 | * Render scene this DOM Object is attached to |
|
156 | * |
||
157 | 8 | * @return string |
|
158 | */ |
||
159 | 8 | public function render(): string |
|
160 | { |
||
161 | 8 | $html = $this->docObj->getElementsByTagName('html')->item(0); |
|
162 | /* Make sure we do not add duplicates when render is called multiple times */ |
||
163 | 8 | if (! $html->hasChildNodes()) { |
|
164 | $this->renderHead(); |
||
165 | |||
166 | $html->appendChild($this->head); |
||
167 | |||
168 | $this->renderBody(); |
||
169 | |||
170 | $html->appendChild($this->body); |
||
171 | 1 | } |
|
172 | return $this->format_output ? $this->correctOutputFormat($this->docObj->saveHTML()) : $this->docObj->saveHTML(); |
||
173 | 1 | } |
|
174 | 1 | ||
175 | /** |
||
176 | * Set Scene meta title |
||
177 | * |
||
178 | * @param string $title |
||
179 | */ |
||
180 | public function setTitle(string $title) |
||
181 | 1 | { |
|
182 | $this->scene_title = $title; |
||
183 | 1 | } |
|
184 | 1 | ||
185 | /** |
||
186 | * Set Scene meta description |
||
187 | * |
||
188 | * @param string $description |
||
189 | */ |
||
190 | public function setDescription(string $description) |
||
191 | { |
||
192 | 19 | $this->scene_description = $description; |
|
193 | } |
||
194 | 19 | ||
195 | 11 | /** |
|
196 | 11 | * Append entities |
|
197 | * |
||
198 | * @param array $entities |
||
199 | 19 | * @return void |
|
200 | */ |
||
201 | public function appendEntities(array $entities) |
||
202 | { |
||
203 | if (! empty($entities)) { |
||
204 | foreach ($entities as $entity) { |
||
205 | $this->appendEntity($entity); |
||
206 | } |
||
207 | 2 | } |
|
208 | } |
||
209 | 2 | ||
210 | 2 | /** |
|
211 | 2 | * Append assets |
|
212 | 2 | * |
|
213 | * @param array $assets |
||
214 | 2 | * @return void |
|
215 | 2 | */ |
|
216 | public function appendAssets(array $assets) |
||
217 | 2 | { |
|
218 | if (! empty($assets)) { |
||
219 | 2 | if ($this->format_output) { |
|
220 | $com = $this->docObj->createComment(''); |
||
221 | $this->scene->appendChild($com); |
||
222 | } |
||
223 | foreach ($assets as $asset) { |
||
224 | $this->appendAsset($asset); |
||
225 | } |
||
226 | $this->scene->appendChild($this->assets); |
||
227 | } |
||
228 | 2 | } |
|
229 | |||
230 | 2 | /** |
|
231 | 2 | * Register scripts to be added to DOM |
|
232 | 2 | * |
|
233 | * @param array $scripts |
||
234 | * @return void |
||
235 | */ |
||
236 | public function registerScripts(array $scripts) |
||
237 | { |
||
238 | $this->scripts = array_merge($this->scripts, $scripts); |
||
239 | } |
||
240 | /** |
||
241 | * Append scripts |
||
242 | 13 | * |
|
243 | * @param array $scripts |
||
244 | 13 | * @return void |
|
245 | 13 | */ |
|
246 | 13 | public function appendScripts(array $scripts) |
|
247 | { |
||
248 | foreach($scripts as $url => $use) { |
||
249 | (!$use)?:$this->appendScript($url); |
||
250 | } |
||
251 | } |
||
252 | |||
253 | 12 | /** |
|
254 | * Append script |
||
255 | 12 | * |
|
256 | 12 | * @param string $script_uri |
|
257 | * @return void |
||
258 | 12 | */ |
|
259 | 12 | public function appendScript(string $script_uri) |
|
260 | 12 | { |
|
261 | $extra_script_url = sprintf('%s%s',$this->assets_uri, $script_uri); |
||
262 | $extra_script = $this->docObj->createElement('script'); |
||
263 | $extra_script->setAttribute('src', $extra_script_url); |
||
264 | $this->head->appendChild($extra_script); |
||
265 | } |
||
266 | /** |
||
267 | * Append asset |
||
268 | * |
||
269 | 19 | * Create asset DOMElement |
|
270 | * |
||
271 | 19 | * @param AssetsInterface $asset |
|
272 | */ |
||
273 | public function appendAsset(AssetsInterface $asset) |
||
274 | { |
||
275 | $this->appendFormatComment('assets', "\n\t"); |
||
276 | 1 | $this->assets->appendChild($asset->domElement($this->docObj)); |
|
277 | 1 | } |
|
278 | |||
279 | 19 | /** |
|
280 | * Create entity DOMElement |
||
281 | * |
||
282 | * Created entity and append it to scene |
||
283 | * |
||
284 | * @param Entity $entity |
||
285 | * @return void |
||
286 | */ |
||
287 | 98 | public function appendEntity(Entity $entity) |
|
292 | 98 | ||
293 | 98 | /** |
|
294 | * Get HTML of Scene only |
||
295 | * |
||
296 | * @return string |
||
297 | */ |
||
298 | public function renderSceneOnly() |
||
299 | { |
||
300 | $html = new DOMDocument(); |
||
301 | $html->formatOutput = $this->format_output; |
||
302 | |||
307 | |||
308 | /** |
||
309 | * Add scene components |
||
310 | * |
||
311 | * @param array $components |
||
312 | * @return void |
||
313 | */ |
||
314 | public function appendSceneComponents(array $components) |
||
325 | |||
326 | /** |
||
327 | * Append DOM attributes no set by components |
||
328 | * |
||
329 | * @param \DOMElement $a_entity |
||
|
|||
330 | */ |
||
331 | public function appendSceneAttributes(array $attrs) |
||
339 | |||
340 | private function appendSceneAttribute($attr, $val) |
||
347 | |||
348 | |||
349 | /** |
||
350 | * Set configuration option related to DOM |
||
351 | * |
||
352 | * @param Config $config |
||
353 | * @return void |
||
354 | */ |
||
355 | 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 | 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.