Mercurial > hg > isophonics-drupal-site
comparison vendor/doctrine/common/lib/Doctrine/Common/Util/ClassUtils.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
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 | |
24 /** | |
25 * Class and reflection related functionality for objects that | |
26 * might or not be proxy objects at the moment. | |
27 * | |
28 * @author Benjamin Eberlei <kontakt@beberlei.de> | |
29 * @author Johannes Schmitt <schmittjoh@gmail.com> | |
30 */ | |
31 class ClassUtils | |
32 { | |
33 /** | |
34 * Gets the real class name of a class name that could be a proxy. | |
35 * | |
36 * @param string $class | |
37 * | |
38 * @return string | |
39 */ | |
40 public static function getRealClass($class) | |
41 { | |
42 if (false === $pos = strrpos($class, '\\'.Proxy::MARKER.'\\')) { | |
43 return $class; | |
44 } | |
45 | |
46 return substr($class, $pos + Proxy::MARKER_LENGTH + 2); | |
47 } | |
48 | |
49 /** | |
50 * Gets the real class name of an object (even if its a proxy). | |
51 * | |
52 * @param object $object | |
53 * | |
54 * @return string | |
55 */ | |
56 public static function getClass($object) | |
57 { | |
58 return self::getRealClass(get_class($object)); | |
59 } | |
60 | |
61 /** | |
62 * Gets the real parent class name of a class or object. | |
63 * | |
64 * @param string $className | |
65 * | |
66 * @return string | |
67 */ | |
68 public static function getParentClass($className) | |
69 { | |
70 return get_parent_class( self::getRealClass( $className ) ); | |
71 } | |
72 | |
73 /** | |
74 * Creates a new reflection class. | |
75 * | |
76 * @param string $class | |
77 * | |
78 * @return \ReflectionClass | |
79 */ | |
80 public static function newReflectionClass($class) | |
81 { | |
82 return new \ReflectionClass( self::getRealClass( $class ) ); | |
83 } | |
84 | |
85 /** | |
86 * Creates a new reflection object. | |
87 * | |
88 * @param object $object | |
89 * | |
90 * @return \ReflectionObject | |
91 */ | |
92 public static function newReflectionObject($object) | |
93 { | |
94 return self::newReflectionClass( self::getClass( $object ) ); | |
95 } | |
96 | |
97 /** | |
98 * Given a class name and a proxy namespace returns the proxy name. | |
99 * | |
100 * @param string $className | |
101 * @param string $proxyNamespace | |
102 * | |
103 * @return string | |
104 */ | |
105 public static function generateProxyClassName($className, $proxyNamespace) | |
106 { | |
107 return rtrim($proxyNamespace, '\\') . '\\'.Proxy::MARKER.'\\' . ltrim($className, '\\'); | |
108 } | |
109 } |