|
1
|
|
|
<?php |
|
2
|
|
|
/** @formatter:off |
|
3
|
|
|
* ****************************************************************** |
|
4
|
|
|
* Created by Marko Kungla on Jun 20, 2016 - 9:01:22 PM |
|
5
|
|
|
* Contact [email protected] |
|
6
|
|
|
* @copyright 2016 Marko Kungla - https://github.com/mkungla |
|
7
|
|
|
* @license The MIT License (MIT) |
|
8
|
|
|
* |
|
9
|
|
|
* @category AframeVR |
|
10
|
|
|
* @package aframe-php |
|
11
|
|
|
* |
|
12
|
|
|
* Lang PHP (php version >= 7) |
|
13
|
|
|
* Encoding UTF-8 |
|
14
|
|
|
* File Scene.php |
|
15
|
|
|
* Code format PSR-2 and 12 |
|
16
|
|
|
* @link https://github.com/mkungla/aframe-php |
|
17
|
|
|
^ @issues https://github.com/mkungla/aframe-php/issues |
|
18
|
|
|
* ******************************************************************** |
|
19
|
|
|
* Contributors: |
|
20
|
|
|
* @author Marko Kungla <[email protected]> |
|
21
|
|
|
* ******************************************************************** |
|
22
|
|
|
* Comments: |
|
23
|
|
|
* @formatter:on */ |
|
24
|
|
|
namespace AframeVR\Core; |
|
25
|
|
|
|
|
26
|
|
|
use \AframeVR\Core\Helpers\MetaTags; |
|
27
|
|
|
use \AframeVR\Extras\Primitives; |
|
28
|
|
|
use \DOMImplementation; |
|
29
|
|
|
|
|
30
|
|
|
final class Scene |
|
31
|
|
|
{ |
|
32
|
|
|
use Primitives; |
|
33
|
|
|
|
|
34
|
|
|
private $name; |
|
35
|
|
|
|
|
36
|
9 |
|
public function __construct($name) |
|
37
|
|
|
{ |
|
38
|
9 |
|
$this->name = $name; |
|
39
|
9 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Scene DOMDocument meta tags object |
|
43
|
|
|
* |
|
44
|
|
|
* @return \AframeVR\Core\Helpers\MetaTags |
|
45
|
|
|
*/ |
|
46
|
|
|
public function meta() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->meta ?? $this->meta = new MetaTags(); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Render the A-Frame scene |
|
53
|
|
|
* |
|
54
|
|
|
* @param string $full |
|
|
|
|
|
|
55
|
|
|
*/ |
|
56
|
|
|
public function render($full = true) |
|
|
|
|
|
|
57
|
|
|
{ |
|
58
|
|
|
$dom = new DOMImplementation(); |
|
59
|
|
|
$doctype = $dom->createDocumentType('html'); |
|
60
|
|
|
$aframe_dom = $dom->createDocument(null, 'html', $doctype); |
|
61
|
|
|
$aframe_dom_head = $aframe_dom->createElement('head'); |
|
62
|
|
|
$aframe_dom_body = $aframe_dom->createElement('body', "\n"); |
|
63
|
|
|
$aframe_dom_scene = $aframe_dom->createElement("a-scene", "\n"); |
|
64
|
|
|
|
|
65
|
|
|
/* Add metatags */ |
|
66
|
|
|
$this->meta()->DOMAppendTags($aframe_dom, $aframe_dom_head); |
|
67
|
|
|
|
|
68
|
|
|
/* Add primitives to DOM */ |
|
69
|
|
|
$this->DOMAppendPrimitives($aframe_dom, $aframe_dom_scene); |
|
70
|
|
|
|
|
71
|
|
|
$cdn_script = $aframe_dom->createElement('script'); |
|
72
|
|
|
$cdn_script->setAttribute('src', 'https://aframe.io/releases/0.2.0/aframe.min.js'); |
|
73
|
|
|
$aframe_dom_head->appendChild($cdn_script); |
|
74
|
|
|
|
|
75
|
|
|
/* Pull DOM together */ |
|
76
|
|
|
$aframe_dom_body->appendChild($aframe_dom_scene); |
|
77
|
|
|
$html = $aframe_dom->getElementsByTagName('html')[0]; |
|
78
|
|
|
$html->appendChild($aframe_dom_head); |
|
79
|
|
|
$html->appendChild($aframe_dom_body); |
|
80
|
|
|
|
|
81
|
|
|
$aframe_dom->formatOutput = true; |
|
82
|
|
|
|
|
83
|
|
|
/* Print Scene */ |
|
84
|
|
|
print $aframe_dom->saveHTML(); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: