|
1
|
|
|
<?php |
|
2
|
|
|
/** @formatter:off |
|
3
|
|
|
* ****************************************************************** |
|
4
|
|
|
* Created by Marko Kungla on Jun 21, 2016 - 12:24:13 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 Cylinder.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\Extras\Primitives; |
|
25
|
|
|
|
|
26
|
|
|
use \AframeVR\Core\Entity; |
|
27
|
|
|
use \AframeVR\Core\Helpers\MeshAttributes; |
|
28
|
|
|
use \AframeVR\Interfaces\PrimitiveInterface; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* <a-cylinder> |
|
32
|
|
|
* |
|
33
|
|
|
* The cylinder primitive is an entity that prescribes the geometry with its geometric primitive set to cylinder. |
|
34
|
|
|
* It can be used to create tubes and curved surfaces. |
|
35
|
|
|
*/ |
|
36
|
|
|
class Cylinder extends Entity implements PrimitiveInterface |
|
37
|
|
|
{ |
|
38
|
|
|
use MeshAttributes; |
|
39
|
|
|
|
|
40
|
4 |
|
public function init() |
|
41
|
|
|
{ |
|
42
|
4 |
|
$this->component('Material'); |
|
43
|
4 |
|
$this->component('Geometry')->primitive('cylinder'); |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/* Load defaults */ |
|
46
|
4 |
|
} |
|
47
|
|
|
|
|
48
|
4 |
|
public function height(float $height = 1) |
|
49
|
|
|
{ |
|
50
|
4 |
|
$this->component('Geometry')->height($height); |
|
|
|
|
|
|
51
|
4 |
|
return $this; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
4 |
|
public function openEnded(bool $openEnded = false) |
|
55
|
|
|
{ |
|
56
|
4 |
|
$this->component('Geometry')->openEnded($openEnded); |
|
|
|
|
|
|
57
|
4 |
|
return $this; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
4 |
|
public function radius(float $radius = 0.75) |
|
61
|
|
|
{ |
|
62
|
4 |
|
$this->component('Geometry')->radius($radius); |
|
|
|
|
|
|
63
|
4 |
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
4 |
|
public function segmentsHeight(int $segmentsHeight = 1) |
|
67
|
|
|
{ |
|
68
|
4 |
|
$this->component('Geometry')->segmentsHeight($segmentsHeight); |
|
|
|
|
|
|
69
|
4 |
|
return $this; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
4 |
|
public function segmentsRadial(int $segmentsRadial = 36) |
|
73
|
|
|
{ |
|
74
|
4 |
|
$this->component('Geometry')->segmentsHeight($segmentsRadial); |
|
|
|
|
|
|
75
|
4 |
|
return $this; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
4 |
|
public function thetaLength(int $thetaLength = 360) |
|
79
|
|
|
{ |
|
80
|
4 |
|
$this->component('Geometry')->thetaLength($thetaLength); |
|
|
|
|
|
|
81
|
4 |
|
return $this; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
4 |
|
public function thetaStart(int $thetaStart = 0) |
|
85
|
|
|
{ |
|
86
|
4 |
|
$this->component('Geometry')->thetaStart($thetaStart); |
|
|
|
|
|
|
87
|
4 |
|
return $this; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
4 |
|
public function defaults() |
|
91
|
|
|
{ |
|
92
|
4 |
|
$this->height(); |
|
93
|
4 |
|
$this->openEnded(); |
|
94
|
4 |
|
$this->radius(); |
|
95
|
4 |
|
$this->segmentsHeight(); |
|
96
|
4 |
|
$this->segmentsRadial(); |
|
97
|
4 |
|
$this->thetaLength(); |
|
98
|
4 |
|
$this->thetaStart(); |
|
99
|
4 |
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: