From 71ba1077286938f653d833f2262514e3a14f39d2 Mon Sep 17 00:00:00 2001 From: Cosmologist Date: Fri, 9 Nov 2018 21:20:57 +0300 Subject: [PATCH] Add DoctrineUtils::getRealClass --- Doctrine/DoctrineUtils.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Doctrine/DoctrineUtils.php b/Doctrine/DoctrineUtils.php index 82ca93c..85d4615 100644 --- a/Doctrine/DoctrineUtils.php +++ b/Doctrine/DoctrineUtils.php @@ -3,6 +3,7 @@ namespace Cosmologist\Bundle\SymfonyCommonBundle\Doctrine; use Cosmologist\Bundle\SymfonyCommonBundle\Exception\DoctrineUtilsException; +use Cosmologist\Gears\ObjectType; use Doctrine\Bundle\DoctrineBundle\Registry; use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\Common\Util\ClassUtils; @@ -26,6 +27,18 @@ public function __construct(Registry $doctrine) $this->doctrine = $doctrine; } + /** + * Get entity real class + * + * @param string|object $target FQCN or object + * + * @return string FQCN + */ + public function getRealClass($target) + { + return ClassUtils::getRealClass(ObjectType::castClass($target)); + } + /** * Get doctrine class metadata * @@ -35,11 +48,7 @@ public function __construct(Registry $doctrine) */ public function getClassMetadata($entity) { - if (is_object($entity)) { - $entity = get_class($entity); - } - - $fqcn = ClassUtils::getRealClass($entity); + $fqcn = $this->getRealClass($entity); if (null === $entityManager = $this->doctrine->getManagerForClass($fqcn)) { throw DoctrineUtilsException::unsupportedClass($fqcn); }