This repository has been archived by the owner on Sep 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
/
RuntimeClassDefinition.php
137 lines (119 loc) · 3.02 KB
/
RuntimeClassDefinition.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
* @author Patsura Dmitry https://github.com/ovr <talk@dmtry.me>
*/
namespace PHPSA\Definition;
use PHPSA\Context;
use PHPSA\Exception\NotImplementedException;
use ReflectionClass;
/**
* Class created from Reflection
*/
class RuntimeClassDefinition extends ClassDefinition
{
/**
* @var ReflectionClass
*/
protected $reflection;
/**
* @param ReflectionClass $reflection
*/
public function __construct(ReflectionClass $reflection)
{
$this->reflection = $reflection;
}
/**
* @param Context $context
* @return $this
*/
public function compile(Context $context)
{
return $this;
}
/**
* @param string $name
* @param boolean|false $inherit
* @return bool
*/
public function hasMethod($name, $inherit = false)
{
return $this->reflection->hasMethod($name);
}
/**
* @param string $name
* @param bool $inherit
* @return bool
*/
public function hasConst($name, $inherit = false)
{
if (!$this->reflection->hasConstant($name)) {
return false;
}
// NOTE: ReflectionClass::hasConstant also checks parent classes, so if $inherit is true, the job is already done.
if ($inherit) {
return true;
}
// but if it's not, we need to make sure that the constant is defined only in the current class. It means that
// we have to check that it has no parent or that the parent does not define the constant.
$parent = $this->reflection->getParentClass();
if (!$parent) {
return true;
}
return !$parent->hasConstant($name);
}
/**
* @param $name
* @param bool $inherit
* @return ReflectionClassMethod
*/
public function getMethod($name, $inherit = false)
{
return new ReflectionClassMethod($this->reflection->getMethod($name));
}
/**
* @param $name
* @param bool $inherit
* @param bool $isParent It's an internal parameter
* @return bool
*/
public function hasProperty($name, $inherit = false, $isParent = true)
{
return $this->reflection->hasProperty($name);
}
/**
* @return string
*/
public function getFilepath()
{
throw new NotImplementedException(__FUNCTION__);
}
/**
* @return bool
*/
public function isAbstract()
{
return $this->reflection->isAbstract();
}
/**
* @return null|RuntimeClassDefinition
*/
public function getExtendsClassDefinition()
{
$parentReflection = $this->reflection->getParentClass();
if (!$parentReflection) {
return null;
}
return new static($parentReflection);
}
/**
* @return null|string
*/
public function getExtendsClass()
{
$parentReflection = $this->reflection->getParentClass();
if (!$parentReflection) {
return null;
}
return $parentReflection->getName();
}
}