1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Persistence\Mapping; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Reflection\RuntimePublicReflectionProperty; |
8
|
|
|
use Doctrine\Common\Reflection\TypedNoDefaultReflectionProperty; |
9
|
|
|
use ReflectionClass; |
10
|
|
|
use ReflectionException; |
11
|
|
|
use ReflectionMethod; |
12
|
|
|
use ReflectionProperty; |
13
|
|
|
use function array_key_exists; |
14
|
|
|
use function class_exists; |
15
|
|
|
use function class_parents; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* PHP Runtime Reflection Service. |
19
|
|
|
*/ |
20
|
|
|
class RuntimeReflectionService implements ReflectionService |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* {@inheritDoc} |
24
|
|
|
*/ |
25
|
2 |
|
public function getParentClasses(string $class) |
26
|
|
|
{ |
27
|
2 |
|
if (! class_exists($class)) { |
28
|
1 |
|
throw MappingException::nonExistingClass($class); |
29
|
|
|
} |
30
|
|
|
|
31
|
1 |
|
return class_parents($class); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritDoc} |
36
|
|
|
*/ |
37
|
1 |
|
public function getClassShortName(string $class) |
38
|
|
|
{ |
39
|
1 |
|
$reflectionClass = new ReflectionClass($class); |
40
|
|
|
|
41
|
1 |
|
return $reflectionClass->getShortName(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritDoc} |
46
|
|
|
*/ |
47
|
1 |
|
public function getClassNamespace(string $class) |
48
|
|
|
{ |
49
|
1 |
|
$reflectionClass = new ReflectionClass($class); |
50
|
|
|
|
51
|
1 |
|
return $reflectionClass->getNamespaceName(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritDoc} |
56
|
|
|
*/ |
57
|
2 |
|
public function getClass(string $class) |
58
|
|
|
{ |
59
|
2 |
|
return new ReflectionClass($class); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritDoc} |
64
|
|
|
*/ |
65
|
1 |
|
public function getAccessibleProperty(string $class, string $property) |
66
|
|
|
{ |
67
|
1 |
|
$reflectionProperty = new ReflectionProperty($class, $property); |
68
|
|
|
|
69
|
1 |
|
if (! array_key_exists($property, $this->getClass($class)->getDefaultProperties())) { |
70
|
|
|
$reflectionProperty = new TypedNoDefaultReflectionProperty($class, $property); |
71
|
1 |
|
} elseif ($reflectionProperty->isPublic()) { |
72
|
1 |
|
$reflectionProperty = new RuntimePublicReflectionProperty($class, $property); |
73
|
|
|
} |
74
|
|
|
|
75
|
1 |
|
$reflectionProperty->setAccessible(true); |
76
|
|
|
|
77
|
1 |
|
return $reflectionProperty; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritDoc} |
82
|
|
|
*/ |
83
|
1 |
|
public function hasPublicMethod(string $class, string $method) |
84
|
|
|
{ |
85
|
|
|
try { |
86
|
1 |
|
$reflectionMethod = new ReflectionMethod($class, $method); |
87
|
1 |
|
} catch (ReflectionException $e) { |
88
|
1 |
|
return false; |
89
|
|
|
} |
90
|
|
|
|
91
|
1 |
|
return $reflectionMethod->isPublic(); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|