1
0
mirror of synced 2025-01-18 22:41:43 +03:00

[DDC-2256] Cleanup patch, move dependency on EntityManager out of ResultSetMapping and let AbstractQuery perform the translation.

This commit is contained in:
Benjamin Eberlei 2013-02-13 09:05:35 +01:00
parent 3d9cb9460a
commit ce594fb152
2 changed files with 20 additions and 25 deletions

View File

@ -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.
*

View File

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