-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathReflectionClassReader.php
More file actions
61 lines (53 loc) · 1.38 KB
/
ReflectionClassReader.php
File metadata and controls
61 lines (53 loc) · 1.38 KB
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
<?php
declare(strict_types=1);
namespace PHPJava\Core\JVM\Stream;
use PHPJava\Core\JVM\Parameters\Runtime;
class ReflectionClassReader implements StreamReaderInterface
{
/**
* @var \ReflectionClass
*/
private $handle;
/**
* @param \ReflectionClass $handle
*/
public function __construct($handle)
{
$this->handle = $handle;
}
/**
* @return \ReflectionProperty[]
*/
public function getFields()
{
$fields = [];
foreach ($this->handle->getProperties() as $field) {
$fieldName = static::removePrefixes($field->getName());
$fields[Runtime::CLASS_INITIALIZER_CLASS_MAPS[$fieldName] ?? $fieldName] = $field;
}
return $fields;
}
/**
* @return \ReflectionMethod[][]
*/
public function getMethods()
{
$methods = [];
foreach ($this->handle->getMethods() as $method) {
$methodName = static::removePrefixes($method->getName());
$methods[Runtime::CLASS_INITIALIZER_CLASS_MAPS[$methodName] ?? $methodName][] = $method;
}
return $methods;
}
private static function removePrefixes(string $name): string
{
return str_replace(
[
Runtime::PREFIX_STATIC,
Runtime::PREFIX_DEFAULT,
],
'',
$name
);
}
}