1 | <?php |
||
36 | trait Primitives |
||
37 | { |
||
38 | |||
39 | protected $spheres; |
||
40 | |||
41 | protected $boxes; |
||
42 | |||
43 | protected $cylinders; |
||
44 | |||
45 | protected $planes; |
||
46 | |||
47 | protected $sky; |
||
48 | |||
49 | /** |
||
50 | * A-Frame Primitive box |
||
51 | * |
||
52 | * @param string $name |
||
53 | * @return Entity |
||
54 | */ |
||
55 | 5 | public function box(string $name = 'untitled'): Entity |
|
56 | { |
||
57 | 5 | return $this->boxes[$name] ?? $this->boxes[$name] = new Box(); |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * A-Frame Primitive camera |
||
62 | * |
||
63 | * @param string $name |
||
64 | * @return Entity |
||
65 | */ |
||
66 | public function camera(string $name = 'untitled'): Entity |
||
70 | |||
71 | /** |
||
72 | * A-Frame Primitive sphere |
||
73 | * |
||
74 | * @param string $name |
||
75 | * @return Entity |
||
76 | */ |
||
77 | 5 | public function sphere(string $name = 'untitled'): Entity |
|
78 | { |
||
79 | 5 | return $this->spheres[$name] ?? $this->spheres[$name] = new Sphere(); |
|
80 | } |
||
81 | |||
82 | |||
83 | |||
84 | /** |
||
85 | * A-Frame Primitive cylinder |
||
86 | * |
||
87 | * @param string $name |
||
88 | * @return Entity |
||
89 | */ |
||
90 | 5 | public function cylinder(string $name = 'untitled'): Entity |
|
94 | |||
95 | /** |
||
96 | * A-Frame Primitive plane |
||
97 | * |
||
98 | * @param string $name |
||
99 | * @return Entity |
||
100 | */ |
||
101 | 5 | public function plane(string $name = 'untitled'): Entity |
|
105 | |||
106 | /** |
||
107 | * A-Frame Primitive sky |
||
108 | * |
||
109 | * @return Entity |
||
110 | */ |
||
111 | 5 | public function sky(): Entity |
|
115 | |||
116 | /** |
||
117 | * Add all used primitevs to the scene |
||
118 | * |
||
119 | * @param \DOMDocument $aframe_dom |
||
120 | * @param \DOMElement $scene |
||
121 | */ |
||
122 | 1 | protected function DOMAppendPrimitives(\DOMDocument &$aframe_dom, \DOMElement &$scene) |
|
158 | } |
||
159 |
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: