Skip to content

Commit

Permalink
Add DoctrineUtils::getRealClass
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosmologist committed Nov 9, 2018
1 parent 6437b4d commit 71ba107
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Doctrine/DoctrineUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*
Expand All @@ -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);
}
Expand Down

0 comments on commit 71ba107

Please sign in to comment.