ClassUtils.php
43 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Doctrine\Common\Util; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Doctrine\Persistence\Proxy; |
| 5 | use ReflectionClass; |
| 6 | use function get_class; |
| 7 | use function get_parent_class; |
| 8 | use function ltrim; |
| 9 | use function rtrim; |
| 10 | use function strrpos; |
| 11 | use function substr; |
| 12 | class ClassUtils |
| 13 | { |
| 14 | public static function getRealClass($className) |
| 15 | { |
| 16 | $pos = strrpos($className, '\\' . Proxy::MARKER . '\\'); |
| 17 | if ($pos === \false) { |
| 18 | return $className; |
| 19 | } |
| 20 | return substr($className, $pos + Proxy::MARKER_LENGTH + 2); |
| 21 | } |
| 22 | public static function getClass($object) |
| 23 | { |
| 24 | return self::getRealClass(get_class($object)); |
| 25 | } |
| 26 | public static function getParentClass($className) |
| 27 | { |
| 28 | return get_parent_class(self::getRealClass($className)); |
| 29 | } |
| 30 | public static function newReflectionClass($className) |
| 31 | { |
| 32 | return new ReflectionClass(self::getRealClass($className)); |
| 33 | } |
| 34 | public static function newReflectionObject($object) |
| 35 | { |
| 36 | return self::newReflectionClass(self::getClass($object)); |
| 37 | } |
| 38 | public static function generateProxyClassName($className, $proxyNamespace) |
| 39 | { |
| 40 | return rtrim($proxyNamespace, '\\') . '\\' . Proxy::MARKER . '\\' . ltrim($className, '\\'); |
| 41 | } |
| 42 | } |
| 43 |