ClassUtils.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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\Core\Util;
  11. use Symfony\Component\Security\Acl\Util\ClassUtils as AclClassUtils;
  12. @trigger_error('The '.__NAMESPACE__.'\ClassUtils class is deprecated since Symfony 2.8, to be removed in 3.0. Use Symfony\Component\Security\Acl\Util\ClassUtils instead.', E_USER_DEPRECATED);
  13. /**
  14. * Class related functionality for objects that
  15. * might or might not be proxy objects at the moment.
  16. *
  17. * @deprecated ClassUtils is deprecated since version 2.8, to be removed in 3.0. Use Acl ClassUtils instead.
  18. *
  19. * @author Benjamin Eberlei <kontakt@beberlei.de>
  20. * @author Johannes Schmitt <schmittjoh@gmail.com>
  21. */
  22. class ClassUtils
  23. {
  24. /**
  25. * Marker for Proxy class names.
  26. */
  27. const MARKER = '__CG__';
  28. /**
  29. * Length of the proxy marker.
  30. */
  31. const MARKER_LENGTH = 6;
  32. /**
  33. * This class should not be instantiated.
  34. */
  35. private function __construct()
  36. {
  37. }
  38. /**
  39. * Gets the real class name of a class name that could be a proxy.
  40. *
  41. * @param string|object $object
  42. *
  43. * @return string
  44. */
  45. public static function getRealClass($object)
  46. {
  47. if (class_exists('Symfony\Component\Security\Acl\Util\ClassUtils')) {
  48. return AclClassUtils::getRealClass($object);
  49. }
  50. // fallback in case security-acl is not installed
  51. $class = \is_object($object) ? \get_class($object) : $object;
  52. if (false === $pos = strrpos($class, '\\'.self::MARKER.'\\')) {
  53. return $class;
  54. }
  55. return substr($class, $pos + self::MARKER_LENGTH + 2);
  56. }
  57. }