1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Kévin Gomez https://github.com/K-Phoen <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace PHPSA\Definition; |
7
|
|
|
|
8
|
|
|
use PHPSA\Context; |
9
|
|
|
use PHPSA\Exception\NotImplementedException; |
10
|
|
|
use ReflectionClass; |
11
|
|
|
|
12
|
|
|
class RuntimeInterfaceDefinition extends InterfaceDefinition |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var ReflectionClass |
16
|
|
|
*/ |
17
|
|
|
protected $reflection; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param ReflectionClass $reflection |
21
|
|
|
*/ |
22
|
|
|
public function __construct(ReflectionClass $reflection) |
23
|
|
|
{ |
24
|
|
|
parent::__construct($reflection->getName()); |
|
|
|
|
25
|
|
|
|
26
|
|
|
$this->reflection = $reflection; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param Context $context |
31
|
|
|
* @return $this |
32
|
|
|
*/ |
33
|
|
|
public function compile(Context $context) |
34
|
|
|
{ |
35
|
|
|
return $this; |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param string $name |
40
|
|
|
* @param boolean|false $inherit |
41
|
|
|
* @return bool |
42
|
|
|
*/ |
43
|
|
|
public function hasMethod($name, $inherit = false) |
44
|
|
|
{ |
45
|
|
|
return $this->reflection->hasMethod($name); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string $name |
50
|
|
|
* @param bool $inherit |
51
|
|
|
* @return bool |
52
|
|
|
*/ |
53
|
|
|
public function hasConst($name, $inherit = false) |
54
|
|
|
{ |
55
|
|
|
if (!$this->reflection->hasConstant($name)) { |
56
|
|
|
return false; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
// NOTE: ReflectionClass::hasConstant also checks parent classes, so if $inherit is true, the job is already done. |
60
|
|
|
if ($inherit) { |
61
|
|
|
return true; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// but if it's not, we need to make sure that the constant is defined only in the current class. It means that |
65
|
|
|
// we have to check that it has no parent or that the parent does not define the constant. |
66
|
|
|
$parent = $this->reflection->getParentClass(); |
67
|
|
|
if (!$parent) { |
68
|
|
|
return true; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return !$parent->hasConstant($name); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param $name |
76
|
|
|
* @param boolean|false $inherit |
77
|
|
|
* @return ReflectionClassMethod |
78
|
|
|
*/ |
79
|
|
|
public function getMethod($name, $inherit = false) |
80
|
|
|
{ |
81
|
|
|
return new ReflectionClassMethod($this->reflection->getMethod($name)); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param $name |
86
|
|
|
* @param bool $inherit |
87
|
|
|
* @return bool |
88
|
|
|
*/ |
89
|
|
|
public function hasProperty($name, $inherit = false) |
|
|
|
|
90
|
|
|
{ |
91
|
|
|
return $this->reflection->hasProperty($name); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
|
|
public function getFilepath() |
98
|
|
|
{ |
99
|
|
|
throw new NotImplementedException(__FUNCTION__); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return bool |
104
|
|
|
*/ |
105
|
|
|
public function isAbstract() |
106
|
|
|
{ |
107
|
|
|
throw new NotImplementedException(__FUNCTION__); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|