ClassUtils.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Security\Acl\Util;
  11. use Doctrine\Common\Util\ClassUtils as DoctrineClassUtils;
  12. /**
  13. * Class related functionality for objects that
  14. * might or might not be proxy objects at the moment.
  15. *
  16. * @see DoctrineClassUtils
  17. *
  18. * @author Johannes Schmitt <schmittjoh@gmail.com>
  19. * @author Iltar van der Berg <kjarli@gmail.com>
  20. */
  21. final class ClassUtils
  22. {
  23. /**
  24. * Marker for Proxy class names.
  25. *
  26. * @var string
  27. */
  28. const MARKER = '__CG__';
  29. /**
  30. * Length of the proxy marker.
  31. *
  32. * @var int
  33. */
  34. const MARKER_LENGTH = 6;
  35. /**
  36. * This class should not be instantiated.
  37. */
  38. private function __construct()
  39. {
  40. }
  41. /**
  42. * Gets the real class name of a class name that could be a proxy.
  43. *
  44. * @param string|object $object
  45. *
  46. * @return string
  47. */
  48. public static function getRealClass($object)
  49. {
  50. $class = is_object($object) ? get_class($object) : $object;
  51. if (class_exists('Doctrine\Common\Util\ClassUtils')) {
  52. return DoctrineClassUtils::getRealClass($class);
  53. }
  54. // fallback in case doctrine common is not installed
  55. if (false === $pos = strrpos($class, '\\'.self::MARKER.'\\')) {
  56. return $class;
  57. }
  58. return substr($class, $pos + self::MARKER_LENGTH + 2);
  59. }
  60. }