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