From 6f90f5a249a7d1c3023b8ee2ea4c884cc81fd624 Mon Sep 17 00:00:00 2001 From: Meritoo Date: Sat, 13 Apr 2019 17:27:06 +0200 Subject: [PATCH] Reflection > fix deprecations --- src/Utilities/Reflection.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Utilities/Reflection.php b/src/Utilities/Reflection.php index 23c9d65..d783cb7 100644 --- a/src/Utilities/Reflection.php +++ b/src/Utilities/Reflection.php @@ -8,8 +8,8 @@ namespace Meritoo\Common\Utilities; -use Doctrine\Common\Util\ClassUtils; -use Doctrine\Common\Util\Inflector; +use Doctrine\Common\Inflector\Inflector; +use Doctrine\Common\Persistence\Proxy; use Meritoo\Common\Collection\Collection; use Meritoo\Common\Exception\Reflection\CannotResolveClassNameException; use Meritoo\Common\Exception\Reflection\MissingChildClassesException; @@ -368,7 +368,7 @@ class Reflection return $name; } - return ClassUtils::getRealClass($name); + return static::getRealClass($name); } /** @@ -514,14 +514,14 @@ class Reflection foreach ($allClasses as $oneClass) { if (self::isChildOfClass($oneClass, $className)) { /* - * Attention. I have to use ClassUtils::getRealClass() method to avoid problem with the proxy / cache + * Attention. I have to use static::getRealClass() method to avoid problem with the proxy / cache * classes. Example: * - My\ExtraBundle\Entity\MyEntity * - Proxies\__CG__\My\ExtraBundle\Entity\MyEntity * * It's actually the same class, so I have to skip it. */ - $realClass = ClassUtils::getRealClass($oneClass); + $realClass = static::getRealClass($oneClass); if (in_array($realClass, $childClasses, true)) { continue; @@ -704,4 +704,19 @@ class Reflection static::setPropertyValue($object, $property, $value); } } + + /** + * Returns the real class name of a class name that could be a proxy + * + * @param string $class Class to verify + * @return string + */ + private static function getRealClass($class): string + { + if (false === $pos = strrpos($class, '\\' . Proxy::MARKER . '\\')) { + return $class; + } + + return substr($class, $pos + Proxy::MARKER_LENGTH + 2); + } }