ClassUtils.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace Doctrine\Common\Util;
  3. use Doctrine\Common\Persistence\Proxy;
  4. /**
  5. * Class and reflection related functionality for objects that
  6. * might or not be proxy objects at the moment.
  7. *
  8. * @author Benjamin Eberlei <kontakt@beberlei.de>
  9. * @author Johannes Schmitt <schmittjoh@gmail.com>
  10. *
  11. * @deprecated The ClassUtils class is deprecated.
  12. */
  13. class ClassUtils
  14. {
  15. /**
  16. * Gets the real class name of a class name that could be a proxy.
  17. *
  18. * @param string $class
  19. *
  20. * @return string
  21. */
  22. public static function getRealClass($class)
  23. {
  24. if (false === $pos = strrpos($class, '\\' . Proxy::MARKER . '\\')) {
  25. return $class;
  26. }
  27. return substr($class, $pos + Proxy::MARKER_LENGTH + 2);
  28. }
  29. /**
  30. * Gets the real class name of an object (even if its a proxy).
  31. *
  32. * @param object $object
  33. *
  34. * @return string
  35. */
  36. public static function getClass($object)
  37. {
  38. return self::getRealClass(get_class($object));
  39. }
  40. /**
  41. * Gets the real parent class name of a class or object.
  42. *
  43. * @param string $className
  44. *
  45. * @return string
  46. */
  47. public static function getParentClass($className)
  48. {
  49. return get_parent_class(self::getRealClass($className));
  50. }
  51. /**
  52. * Creates a new reflection class.
  53. *
  54. * @param string $class
  55. *
  56. * @return \ReflectionClass
  57. */
  58. public static function newReflectionClass($class)
  59. {
  60. return new \ReflectionClass(self::getRealClass($class));
  61. }
  62. /**
  63. * Creates a new reflection object.
  64. *
  65. * @param object $object
  66. *
  67. * @return \ReflectionClass
  68. */
  69. public static function newReflectionObject($object)
  70. {
  71. return self::newReflectionClass(self::getClass($object));
  72. }
  73. /**
  74. * Given a class name and a proxy namespace returns the proxy name.
  75. *
  76. * @param string $className
  77. * @param string $proxyNamespace
  78. *
  79. * @return string
  80. */
  81. public static function generateProxyClassName($className, $proxyNamespace)
  82. {
  83. return rtrim($proxyNamespace, '\\') . '\\' . Proxy::MARKER . '\\' . ltrim($className, '\\');
  84. }
  85. }