[DDC-2256] Cleanup patch, move dependency on EntityManager out of ResultSetMapping and let AbstractQuery perform the translation.
This commit is contained in:
parent
3d9cb9460a
commit
ce594fb152
@ -296,12 +296,31 @@ abstract class AbstractQuery
|
||||
*/
|
||||
public function setResultSetMapping(Query\ResultSetMapping $rsm)
|
||||
{
|
||||
$rsm->translateNamespaces($this->_em);
|
||||
$this->translateNamespaces($rsm);
|
||||
$this->_resultSetMapping = $rsm;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to translate entity namespaces to full qualified names.
|
||||
*
|
||||
* @param EntityManager $em
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function translateNamespaces(Query\ResultSetMapping $rsm)
|
||||
{
|
||||
$entityManager = $this->_em;
|
||||
|
||||
$translate = function ($alias) use ($entityManager) {
|
||||
return $entityManager->getClassMetadata($alias)->getName();
|
||||
};
|
||||
|
||||
$rsm->aliasMap = array_map($translate, $rsm->aliasMap);
|
||||
$rsm->declaringClasses = array_map($translate, $rsm->declaringClasses);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a cache profile for hydration caching.
|
||||
*
|
||||
|
@ -19,8 +19,6 @@
|
||||
|
||||
namespace Doctrine\ORM\Query;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
/**
|
||||
* A ResultSetMapping describes how a result set of an SQL query maps to a Doctrine result.
|
||||
*
|
||||
@ -545,27 +543,5 @@ class ResultSetMapping
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to translate entity namespaces to full qualified names.
|
||||
*
|
||||
* @param EntityManager $em
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function translateNamespaces(EntityManager $em)
|
||||
{
|
||||
$fqcn = array();
|
||||
|
||||
$translate = function (&$alias) use ($em, &$fqcn) {
|
||||
if ( ! isset($fqcn[$alias])) {
|
||||
$fqcn[$alias] = $em->getClassMetadata($alias)->getName();
|
||||
}
|
||||
$alias = $fqcn[$alias];
|
||||
};
|
||||
|
||||
array_walk($this->aliasMap, $translate);
|
||||
array_walk($this->declaringClasses, $translate);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user