I have the following code:
namespace Acme\\StoreBundle\\Entity;
use Doctrine\\ORM\\Mapping as ORM;
/**
* Acme\\StoreBundle\\Entity\\User
*
* @ORM\\Tabl
getClassMetadata() is deprecated and will be removed in the future. Use getMetadataFor() instead:
$entityName = $this->em->getMetadataFactory()->getMetadataFor(get_class($entity))->getName();
Or a complete function:
/**
* Returns Doctrine entity name
*
* @param mixed $entity
*
* @return string
* @throws \Exception
*/
private function getEntityName($entity)
{
try {
$entityName = $this->em->getMetadataFactory()->getMetadataFor(get_class($entity))->getName();
} catch (MappingException $e) {
throw new \Exception('Given object ' . get_class($entity) . ' is not a Doctrine Entity. ');
}
return $entityName;
}