1
0
mirror of synced 2024-12-13 14:56:01 +03:00

[DDC-2055] Some adjustments to ResultSetMappingBuildder patch

This commit is contained in:
Benjamin Eberlei 2012-11-19 16:54:56 +01:00
parent 9ea40edb48
commit 17bb564534
2 changed files with 25 additions and 16 deletions

View File

@ -69,11 +69,20 @@ class ResultSetMappingBuilder extends ResultSetMapping
private $em;
/**
* @param EntityManager
* Default column renaming mode.
*
* @var int
*/
public function __construct(EntityManager $em)
private $defaultRenameMode;
/**
* @param EntityManager $em
* @param integer $defaultRenameMode
*/
public function __construct(EntityManager $em, $defaultRenameMode = self::COLUMN_RENAMING_NONE)
{
$this->em = $em;
$this->em = $em;
$this->defaultRenameMode = $defaultRenameMode;
}
/**
@ -81,11 +90,12 @@ class ResultSetMappingBuilder extends ResultSetMapping
*
* @param string $class The class name of the root entity.
* @param string $alias The unique alias to use for the root entity.
* @param int|array $renameMode One of the COLUMN_RENAMING_* constants or array for BC reasons (CUSTOM).
* @param array $renamedColumns Columns that have been renamed (tableColumnName => queryColumnName)
* @param int $renameMode One of the COLUMN_RENAMING_* constants or array for BC reasons (CUSTOM).
*/
public function addRootEntityFromClassMetadata($class, $alias, $renameMode = self::COLUMN_RENAMING_NONE, $renamedColumns = array())
public function addRootEntityFromClassMetadata($class, $alias, $renamedColumns = array(), $renameMode = null)
{
$renameMode = $renameMode ?: $this->defaultRenameMode;
$columnAliasMap = $this->getColumnAliasMap($class, $renameMode, $renamedColumns);
$this->addEntityResult($class, $alias);
@ -99,11 +109,12 @@ class ResultSetMappingBuilder extends ResultSetMapping
* @param string $alias The unique alias to use for the joined entity.
* @param string $parentAlias The alias of the entity result that is the parent of this joined result.
* @param object $relation The association field that connects the parent entity result with the joined entity result.
* @param int|array $renameMode
* @param array $renamedColumns Columns that have been renamed (tableColumnName => queryColumnName)
* @param int $renameMode One of the COLUMN_RENAMING_* constants or array for BC reasons (CUSTOM).
*/
public function addJoinedEntityFromClassMetadata($class, $alias, $parentAlias, $relation, $renameMode = self::COLUMN_RENAMING_NONE, $renamedColumns = array())
public function addJoinedEntityFromClassMetadata($class, $alias, $parentAlias, $relation, $renamedColumns = array(), $renameMode = null)
{
$renameMode = $renameMode ?: $this->defaultRenameMode;
$columnAliasMap = $this->getColumnAliasMap($class, $renameMode, $renamedColumns);
$this->addJoinedEntityResult($class, $alias, $parentAlias, $relation);
@ -182,16 +193,15 @@ class ResultSetMappingBuilder extends ResultSetMapping
* This depends on the renaming mode selected by the user.
*
* @param string $className
* @param int|array $mode
* @param int $mode
* @param array $customRenameColumns
*
* @return array
*/
private function getColumnAliasMap($className, $mode, array $customRenameColumns)
{
if (is_array($mode)) {
$customRenameColumns = $mode;
$mode = self::COLUMN_RENAMING_CUSTOM;
if ($customRenameColumns) { // for BC with 2.2-2.3 API
$mode = self::COLUMN_RENAMING_CUSTOM;
}
$columnAlias = array();
@ -241,7 +251,6 @@ class ResultSetMappingBuilder extends ResultSetMapping
*/
public function addNamedNativeQueryResultClassMapping(ClassMetadataInfo $class, $resultClassName)
{
$classMetadata = $this->em->getClassMetadata($resultClassName);
$shortName = $classMetadata->reflClass->getShortName();
$alias = strtolower($shortName[0]).'0';

View File

@ -756,8 +756,8 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
*/
public function testGenerateSelectClauseIncrement()
{
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u', ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT);
$rsm = new ResultSetMappingBuilder($this->_em, ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT);
$rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u');
$selectClause = $rsm->generateSelectClause();
@ -769,8 +769,8 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
*/
public function testGenerateSelectClauseToString()
{
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u', ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT);
$rsm = new ResultSetMappingBuilder($this->_em, ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT);
$rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u');
$this->assertEquals('u.id AS id0, u.status AS status1, u.username AS username2, u.name AS name3, u.email_id AS email_id4', (string)$rsm);
}