|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. For more information, see |
|
17
|
|
|
* <http://www.doctrine-project.org>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Doctrine\Common\Util; |
|
21
|
|
|
|
|
22
|
|
|
use Doctrine\Common\Persistence\Proxy; |
|
23
|
|
|
use ProxyManager\Configuration; |
|
24
|
|
|
use ProxyManager\Inflector\ClassNameInflectorInterface; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Class and reflection related functionality for objects that |
|
28
|
|
|
* might or not be proxy objects at the moment. |
|
29
|
|
|
* |
|
30
|
|
|
* @author Benjamin Eberlei <[email protected]> |
|
31
|
|
|
* @author Johannes Schmitt <[email protected]> |
|
32
|
|
|
* |
|
33
|
|
|
* @TODO this class is a shim: we just keep it for now |
|
34
|
|
|
* @TODO all layers of Doctrine\ORM should stop relying on it |
|
35
|
|
|
* |
|
36
|
|
|
* @deprecated please remove references from this class, and instead inject a class name inflector |
|
37
|
|
|
*/ |
|
38
|
|
|
class ClassUtils |
|
39
|
|
|
{ |
|
40
|
|
|
/** |
|
41
|
|
|
* @var ClassNameInflectorInterface|null |
|
42
|
|
|
*/ |
|
43
|
|
|
private static $classNameInflector; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Gets the real class name of a class name that could be a proxy. |
|
47
|
|
|
* |
|
48
|
|
|
* @param string $class |
|
49
|
|
|
* |
|
50
|
|
|
* @return string |
|
51
|
|
|
*/ |
|
52
|
|
|
public static function getRealClass($class) |
|
53
|
|
|
{ |
|
54
|
|
|
if (! self::$classNameInflector) { |
|
55
|
|
|
self::$classNameInflector = (new Configuration())->getClassNameInflector(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$class = self::$classNameInflector->getUserClassName($class); |
|
59
|
|
|
|
|
60
|
|
|
if (false === $pos = strrpos($class, '\\' . Proxy::MARKER . '\\')) { |
|
61
|
|
|
return $class; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return substr($class, $pos + Proxy::MARKER_LENGTH + 2); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Gets the real class name of an object (even if its a proxy). |
|
69
|
|
|
* |
|
70
|
|
|
* @param object $object |
|
71
|
|
|
* |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
|
|
public static function getClass($object) |
|
75
|
|
|
{ |
|
76
|
|
|
return self::getRealClass(get_class($object)); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Gets the real parent class name of a class or object. |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $className |
|
83
|
|
|
* |
|
84
|
|
|
* @return string |
|
85
|
|
|
*/ |
|
86
|
|
|
public static function getParentClass($className) |
|
87
|
|
|
{ |
|
88
|
|
|
return get_parent_class(self::getRealClass($className)); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Creates a new reflection class. |
|
93
|
|
|
* |
|
94
|
|
|
* @param string $class |
|
95
|
|
|
* |
|
96
|
|
|
* @return \ReflectionClass |
|
97
|
|
|
*/ |
|
98
|
|
|
public static function newReflectionClass($class) |
|
99
|
|
|
{ |
|
100
|
|
|
return new \ReflectionClass(self::getRealClass($class)); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Creates a new reflection object. |
|
105
|
|
|
* |
|
106
|
|
|
* @param object $object |
|
107
|
|
|
* |
|
108
|
|
|
* @return \ReflectionClass |
|
109
|
|
|
*/ |
|
110
|
|
|
public static function newReflectionObject($object) |
|
111
|
|
|
{ |
|
112
|
|
|
return self::newReflectionClass(self::getClass($object)); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Given a class name and a proxy namespace returns the proxy name. |
|
117
|
|
|
* |
|
118
|
|
|
* @param string $className |
|
119
|
|
|
* @param string $proxyNamespace |
|
120
|
|
|
* |
|
121
|
|
|
* @return string |
|
122
|
|
|
*/ |
|
123
|
|
|
public static function generateProxyClassName($className, $proxyNamespace) |
|
|
|
|
|
|
124
|
|
|
{ |
|
125
|
|
|
if (! self::$classNameInflector) { |
|
126
|
|
|
self::$classNameInflector = (new Configuration())->getClassNameInflector(); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
return self::$classNameInflector->getProxyClassName($className); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.