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); }