source: pro-violet-viettel/sourcecode/application/libraries/Doctrine/Common/Util/ClassUtils.php @ 345

Last change on this file since 345 was 345, checked in by quyenla, 11 years ago

collaborator page

File size: 3.0 KB
Line 
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 LGPL. For more information, see
17 * <http://www.doctrine-project.org>.
18 */
19
20namespace Doctrine\Common\Util;
21
22use 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 */
31class ClassUtils
32{
33    /**
34     * Get the real class name of a class name that could be a proxy.
35     *
36     * @param string
37     * @return string
38     */
39    public static function getRealClass($class)
40    {
41        if (false === $pos = strrpos($class, '\\'.Proxy::MARKER.'\\')) {
42            return $class;
43        }
44
45        return substr($class, $pos + Proxy::MARKER_LENGTH + 2);
46    }
47
48    /**
49     * Get the real class name of an object (even if its a proxy)
50     *
51     * @param object
52     * @return string
53     */
54    public static function getClass($object)
55    {
56        return self::getRealClass(get_class($object));
57    }
58
59    /**
60     * Get the real parent class name of a class or object
61     *
62     * @param string
63     * @return string
64     */
65    public static function getParentClass($className)
66    {
67        return get_parent_class( self::getRealClass( $className ) );
68    }
69
70    /**
71     * Create a new reflection class
72     *
73     * @param string
74     * @return ReflectionClass
75     */
76    public static function newReflectionClass($class)
77    {
78        return new \ReflectionClass( self::getRealClass( $class ) );
79    }
80
81    /**
82     * Create a new reflection object
83     *
84     * @param object
85     * @return ReflectionObject
86     */
87    public static function newReflectionObject($object)
88    {
89        return self::newReflectionClass( self::getClass( $object ) );
90    }
91
92    /**
93     * Given a class name and a proxy namespace return the proxy name.
94     *
95     * @param string $className
96     * @param string $proxyNamespace
97     * @return string
98     */
99    public static function generateProxyClassName($className, $proxyNamespace)
100    {
101        return rtrim($proxyNamespace, '\\') . '\\'.Proxy::MARKER.'\\' . ltrim($className, '\\');
102    }
103}
Note: See TracBrowser for help on using the repository browser.