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.
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>.
20 namespace Doctrine\Common\Util;
22 use Doctrine\Common\Persistence\Proxy;
25 * Class and reflection related functionality for objects that
26 * might or not be proxy objects at the moment.
28 * @author Benjamin Eberlei <kontakt@beberlei.de>
29 * @author Johannes Schmitt <schmittjoh@gmail.com>
34 * Get the real class name of a class name that could be a proxy.
39 public static function getRealClass($class)
41 if (false === $pos = strrpos($class, '\\'.Proxy::MARKER.'\\')) {
45 return substr($class, $pos + Proxy::MARKER_LENGTH + 2);
49 * Get the real class name of an object (even if its a proxy)
54 public static function getClass($object)
56 return self::getRealClass(get_class($object));
60 * Get the real parent class name of a class or object
65 public static function getParentClass($className)
67 return get_parent_class( self::getRealClass( $className ) );
71 * Create a new reflection class
74 * @return \ReflectionClass
76 public static function newReflectionClass($class)
78 return new \ReflectionClass( self::getRealClass( $class ) );
82 * Create a new reflection object
85 * @return \ReflectionObject
87 public static function newReflectionObject($object)
89 return self::newReflectionClass( self::getClass( $object ) );
93 * Given a class name and a proxy namespace return the proxy name.
95 * @param string $className
96 * @param string $proxyNamespace
99 public static function generateProxyClassName($className, $proxyNamespace)
101 return rtrim($proxyNamespace, '\\') . '\\'.Proxy::MARKER.'\\' . ltrim($className, '\\');