1 | <?php |
||
33 | class Entity implements EntityInterface |
||
34 | { |
||
35 | |||
36 | protected $components = array(); |
||
37 | |||
38 | public function __construct() |
||
57 | |||
58 | /** |
||
59 | * Position component |
||
60 | * |
||
61 | * All entities inherently have the position component. |
||
62 | * |
||
63 | * @param number $x |
||
64 | * @param number $y |
||
65 | * @param number $z |
||
66 | * @return Entity |
||
67 | */ |
||
68 | public function position($x = 0, $y = 0, $z = 0): EntityInterface |
||
73 | |||
74 | /** |
||
75 | * Rotation component |
||
76 | * |
||
77 | * All entities inherently have the rotation component. |
||
78 | * |
||
79 | * @param number $x |
||
80 | * @param number $y |
||
81 | * @param number $z |
||
82 | * @return EntityInterface |
||
83 | */ |
||
84 | public function rotation($x = 0, $y = 0, $z = 0): EntityInterface |
||
89 | |||
90 | /** |
||
91 | * Scale component |
||
92 | * |
||
93 | * All entities inherently have the scale component. |
||
94 | * |
||
95 | * @param number $x |
||
96 | * @param number $y |
||
97 | * @param number $z |
||
98 | * @return EntityInterface |
||
99 | */ |
||
100 | public function scale($x = 0, $y = 0, $z = 0): EntityInterface |
||
105 | |||
106 | /** |
||
107 | * Load component for this entity |
||
108 | * |
||
109 | * @param string $component_name |
||
110 | * @throws BadComponentCallException |
||
111 | * @return ComponentInterface |
||
112 | */ |
||
113 | public function component(string $component_name): ComponentInterface |
||
132 | |||
133 | /** |
||
134 | * Handle entity components |
||
135 | * |
||
136 | * Since we might need to customize these to have |
||
137 | * custom components loaded as $this->methosd aswell therefore |
||
138 | * we have these placeholder magic methods here |
||
139 | * |
||
140 | * @param string $component_name |
||
141 | * @param array $args |
||
142 | */ |
||
143 | public function __call(string $component_name, array $args) |
||
147 | |||
148 | /** |
||
149 | * Create and add DOM element of the entity |
||
150 | * |
||
151 | * @param unknown $aframe_dom |
||
152 | * @return DOMElement |
||
153 | */ |
||
154 | public function DOMElement(&$aframe_dom): DOMElement |
||
172 | } |
||
173 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: