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