1
|
|
|
<?php |
2
|
|
|
/** @formatter:off |
3
|
|
|
* ****************************************************************** |
4
|
|
|
* Created by Marko Kungla on Jul 5, 2016 - 3:05:38 AM |
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 EntityChildrenFactory.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\Helpers; |
25
|
|
|
|
26
|
|
|
use \AframeVR\Core\Entity; |
27
|
|
|
use \AframeVR\Core\Exceptions\BadPrimitiveCallException; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @method \AframeVR\Core\Entity entity(string $id) |
31
|
|
|
* @method \AframeVR\Extras\Primitives\Box box(string $id) |
32
|
|
|
* @method \AframeVR\Extras\Primitives\Camera camera(string $id) |
33
|
|
|
* @method \AframeVR\Extras\Primitives\Circle circle(string $id) |
34
|
|
|
* @method \AframeVR\Extras\Primitives\Colladamodel colladamodel(string $id) |
35
|
|
|
* @method \AframeVR\Extras\Primitives\Cone cone(string $id) |
36
|
|
|
* @method \AframeVR\Extras\Primitives\Cursor cursor(string $id) |
37
|
|
|
* @method \AframeVR\Extras\Primitives\Curvedimage curvedimage(string $id) |
38
|
|
|
* @method \AframeVR\Extras\Primitives\Cylinder cylinder(string $id) |
39
|
|
|
* @method \AframeVR\Extras\Primitives\Image image(string $id) |
40
|
|
|
* @method \AframeVR\Extras\Primitives\Light light(string $id) |
41
|
|
|
* @method \AframeVR\Extras\Primitives\Objmodel objmodel(string $id) |
42
|
|
|
* @method \AframeVR\Extras\Primitives\Plane plane(string $id) |
43
|
|
|
* @method \AframeVR\Extras\Primitives\Ring ring(string $id) |
44
|
|
|
* @method \AframeVR\Extras\Primitives\Sky sky(string $id) |
45
|
|
|
* @method \AframeVR\Extras\Primitives\Sphere sphere(string $id) |
46
|
|
|
* @method \AframeVR\Extras\Primitives\Torus torus(string $id) |
47
|
|
|
* @method \AframeVR\Extras\Primitives\Video video(string $id) |
48
|
|
|
* @method \AframeVR\Extras\Primitives\Videosphere videosphere(string $id) |
49
|
|
|
*/ |
50
|
|
|
|
51
|
|
|
class EntityChildrenFactory |
52
|
|
|
{ |
53
|
|
|
/** |
54
|
|
|
* Child entities |
55
|
|
|
* |
56
|
|
|
* @var array |
57
|
|
|
*/ |
58
|
|
|
private $childrens = array(); |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get entity |
62
|
|
|
* |
63
|
|
|
* @param string $a_type |
64
|
|
|
* @param string $id |
|
|
|
|
65
|
|
|
* @return AframeVR\Interfaces\EntityInterface |
66
|
|
|
*/ |
67
|
77 |
|
public function getEntity(string $a_type, string $entity_id) |
68
|
|
|
{ |
69
|
77 |
|
$id = $id ?? 0; |
|
|
|
|
70
|
77 |
|
return $this->childrens[$a_type][$entity_id] ?? $this->addEntity($a_type, $entity_id); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get all children for calling parent |
75
|
|
|
* @return array |
76
|
|
|
*/ |
77
|
19 |
|
public function getChildren() |
78
|
|
|
{ |
79
|
19 |
|
return iterator_to_array($this->getChildrenRAW($this->childrens), false); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Get entity |
84
|
|
|
* |
85
|
|
|
* @param string $method |
86
|
|
|
* @param array $args |
|
|
|
|
87
|
|
|
* @return AframeVR\Interfaces\EntityInterface |
88
|
|
|
*/ |
89
|
6 |
|
public function __call(string $method, array $entity_id) |
90
|
|
|
{ |
91
|
6 |
|
$entity_id = $entity_id[0] ?? 0; |
|
|
|
|
92
|
6 |
|
return $this->getEntity($method, $entity_id); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Register new entity |
97
|
|
|
* |
98
|
|
|
* Generally you should not call this method directly but if you want to extend |
99
|
|
|
* EntityChildrenFactory then you can still access it |
100
|
|
|
* |
101
|
|
|
* @param string $a_type |
102
|
|
|
* @param string $id |
|
|
|
|
103
|
|
|
* @throws BadShaderCallException |
104
|
|
|
* @return AframeVR\Interfaces\EntityInterface |
105
|
|
|
*/ |
106
|
77 |
|
protected function addEntity(string $a_type, string $entity_id) |
107
|
|
|
{ |
108
|
77 |
|
$primitive = sprintf('\AframeVR\Extras\Primitives\%s', ucfirst($a_type)); |
109
|
|
|
|
110
|
77 |
|
if($a_type === 'entity') { |
111
|
55 |
|
return $this->childrens[$a_type][$entity_id] = new Entity($entity_id); |
112
|
27 |
|
} elseif (class_exists($primitive)) { |
113
|
27 |
|
return $this->childrens[$a_type][$entity_id] = new $primitive($entity_id); |
114
|
|
|
} else { |
115
|
1 |
|
throw new BadPrimitiveCallException($a_type); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Generate array of children |
121
|
|
|
* |
122
|
|
|
* @param array $array |
123
|
|
|
*/ |
124
|
19 |
|
protected function getChildrenRAW(array $array) { |
125
|
19 |
|
foreach ($array as $value) { |
126
|
11 |
|
if (is_array($value)) { |
127
|
11 |
|
yield from $this->getChildrenRAW($value); |
128
|
|
|
} else { |
129
|
11 |
|
yield $value; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
} |
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.