|
1
|
|
|
<?php |
|
2
|
|
|
namespace Doctrine\Common\Util; |
|
3
|
|
|
|
|
4
|
|
|
use Doctrine\Common\Persistence\Proxy; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Class and reflection related functionality for objects that |
|
8
|
|
|
* might or not be proxy objects at the moment. |
|
9
|
|
|
* |
|
10
|
|
|
* @author Benjamin Eberlei <[email protected]> |
|
11
|
|
|
* @author Johannes Schmitt <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class ClassUtils |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Gets the real class name of a class name that could be a proxy. |
|
17
|
|
|
* |
|
18
|
|
|
* @param string $class |
|
19
|
|
|
* |
|
20
|
|
|
* @return string |
|
21
|
|
|
*/ |
|
22
|
|
|
public static function getRealClass($class) |
|
23
|
|
|
{ |
|
24
|
|
|
if (false === $pos = strrpos($class, '\\' . Proxy::MARKER . '\\')) { |
|
25
|
|
|
return $class; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
return substr($class, $pos + Proxy::MARKER_LENGTH + 2); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Gets the real class name of an object (even if its a proxy). |
|
33
|
|
|
* |
|
34
|
|
|
* @param object $object |
|
35
|
|
|
* |
|
36
|
|
|
* @return string |
|
37
|
|
|
*/ |
|
38
|
|
|
public static function getClass($object) |
|
39
|
|
|
{ |
|
40
|
|
|
return self::getRealClass(get_class($object)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Gets the real parent class name of a class or object. |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $className |
|
47
|
|
|
* |
|
48
|
|
|
* @return string |
|
49
|
|
|
*/ |
|
50
|
|
|
public static function getParentClass($className) |
|
51
|
|
|
{ |
|
52
|
|
|
return get_parent_class(self::getRealClass($className)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Creates a new reflection class. |
|
57
|
|
|
* |
|
58
|
|
|
* @param string $class |
|
59
|
|
|
* |
|
60
|
|
|
* @return \ReflectionClass |
|
61
|
|
|
*/ |
|
62
|
|
|
public static function newReflectionClass($class) |
|
63
|
|
|
{ |
|
64
|
|
|
return new \ReflectionClass(self::getRealClass($class)); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Creates a new reflection object. |
|
69
|
|
|
* |
|
70
|
|
|
* @param object $object |
|
71
|
|
|
* |
|
72
|
|
|
* @return \ReflectionClass |
|
73
|
|
|
*/ |
|
74
|
|
|
public static function newReflectionObject($object) |
|
75
|
|
|
{ |
|
76
|
|
|
return self::newReflectionClass(self::getClass($object)); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Given a class name and a proxy namespace returns the proxy name. |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $className |
|
83
|
|
|
* @param string $proxyNamespace |
|
84
|
|
|
* |
|
85
|
|
|
* @return string |
|
86
|
|
|
*/ |
|
87
|
|
|
public static function generateProxyClassName($className, $proxyNamespace) |
|
88
|
|
|
{ |
|
89
|
|
|
return rtrim($proxyNamespace, '\\') . '\\' . Proxy::MARKER . '\\' . ltrim($className, '\\'); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|