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 * Gets the real class name of a class name that could be a proxy.
36 * @param string $class
40 public static function getRealClass($class)
42 if (false === $pos = strrpos($class, '\\'.Proxy::MARKER.'\\')) {
46 return substr($class, $pos + Proxy::MARKER_LENGTH + 2);
50 * Gets the real class name of an object (even if its a proxy).
52 * @param object $object
56 public static function getClass($object)
58 return self::getRealClass(get_class($object));
62 * Gets the real parent class name of a class or object.
64 * @param string $className
68 public static function getParentClass($className)
70 return get_parent_class( self::getRealClass( $className ) );
74 * Creates a new reflection class.
76 * @param string $class
78 * @return \ReflectionClass
80 public static function newReflectionClass($class)
82 return new \ReflectionClass( self::getRealClass( $class ) );
86 * Creates a new reflection object.
88 * @param object $object
90 * @return \ReflectionClass
92 public static function newReflectionObject($object)
94 return self::newReflectionClass( self::getClass( $object ) );
98 * Given a class name and a proxy namespace returns the proxy name.
100 * @param string $className
101 * @param string $proxyNamespace
105 public static function generateProxyClassName($className, $proxyNamespace)
107 return rtrim($proxyNamespace, '\\') . '\\'.Proxy::MARKER.'\\' . ltrim($className, '\\');