parse nested new operators
This commit is contained in:
parent
2b403b7dad
commit
88f04b5ebd
@ -1680,10 +1680,8 @@ class Parser
|
|||||||
|
|
||||||
return new AST\SimpleSelectExpression($expression);
|
return new AST\SimpleSelectExpression($expression);
|
||||||
|
|
||||||
case ($peek['type'] !== Lexer::T_OPEN_PARENTHESIS):
|
case ($this->_lexer->lookahead['type'] === Lexer::T_NEW):
|
||||||
$expression = $this->IdentificationVariable();
|
return $this->NewObjectExpression();
|
||||||
|
|
||||||
return new AST\SimpleSelectExpression($expression);
|
|
||||||
|
|
||||||
case ($this->_isFunction()):
|
case ($this->_isFunction()):
|
||||||
// SUM(u.id) + COUNT(u.id)
|
// SUM(u.id) + COUNT(u.id)
|
||||||
|
@ -1229,28 +1229,7 @@ class SqlWalker implements TreeWalker
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ($expr instanceof AST\NewObjectExpression):
|
case ($expr instanceof AST\NewObjectExpression):
|
||||||
|
$sql .= $this->walkNewObject($expr);
|
||||||
$sqlSelectExpressions = array();
|
|
||||||
$objIndex = $this->newObjectCounter ++;
|
|
||||||
foreach ($expr->args as $argIndex => $e) {
|
|
||||||
|
|
||||||
$resultAlias = $this->scalarResultCounter++;
|
|
||||||
$columnAlias = $this->getSQLColumnAlias('sclr') . $resultAlias;
|
|
||||||
$resultAliasMap = $this->scalarResultAliasMap;
|
|
||||||
$sqlSelectExpressions[] = $this->walkSimpleSelectExpression($e) . ' AS ' . $columnAlias;
|
|
||||||
|
|
||||||
|
|
||||||
$this->scalarResultAliasMap[$resultAlias] = $columnAlias;
|
|
||||||
$this->rsm->addScalarResult($columnAlias, $resultAlias, 'string');
|
|
||||||
|
|
||||||
$this->rsm->newObjectMappings[$columnAlias] = array(
|
|
||||||
'className' => $expr->className,
|
|
||||||
'objIndex' => $objIndex,
|
|
||||||
'argIndex' => $argIndex
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql .= implode(',', $sqlSelectExpressions);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -1419,6 +1398,47 @@ class SqlWalker implements TreeWalker
|
|||||||
. $this->walkSimpleSelectExpression($simpleSelectClause->simpleSelectExpression);
|
. $this->walkSimpleSelectExpression($simpleSelectClause->simpleSelectExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param AST\NewObjectExpression
|
||||||
|
* @return string The SQL.
|
||||||
|
*/
|
||||||
|
public function walkNewObject($newObjectExpression)
|
||||||
|
{
|
||||||
|
|
||||||
|
$sqlSelectExpressions = array();
|
||||||
|
$objIndex = $this->newObjectCounter ++;
|
||||||
|
foreach ($newObjectExpression->args as $argIndex => $e) {
|
||||||
|
|
||||||
|
$resultAlias = $this->scalarResultCounter++;
|
||||||
|
$columnAlias = $this->getSQLColumnAlias('sclr') . $resultAlias;
|
||||||
|
$resultAliasMap = $this->scalarResultAliasMap;
|
||||||
|
|
||||||
|
switch (true) {
|
||||||
|
case $e instanceof AST\NewObjectExpression:
|
||||||
|
|
||||||
|
$sqlSelectExpressions[] = $e->dispatch($this);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
$sqlSelectExpressions[] = $e->dispatch($this) . ' AS ' . $columnAlias;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$this->scalarResultAliasMap[$resultAlias] = $columnAlias;
|
||||||
|
$this->rsm->addScalarResult($columnAlias, $resultAlias, 'string');
|
||||||
|
|
||||||
|
$this->rsm->newObjectMappings[$columnAlias] = array(
|
||||||
|
'className' => $newObjectExpression->className,
|
||||||
|
'objIndex' => $objIndex,
|
||||||
|
'argIndex' => $argIndex
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(',', $sqlSelectExpressions);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Walks down a SimpleSelectExpression AST node, thereby generating the appropriate SQL.
|
* Walks down a SimpleSelectExpression AST node, thereby generating the appropriate SQL.
|
||||||
*
|
*
|
||||||
|
@ -129,7 +129,11 @@ class NewOperatorTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
new Doctrine\Tests\Models\CMS\CmsUserDTO(
|
new Doctrine\Tests\Models\CMS\CmsUserDTO(
|
||||||
u.name,
|
u.name,
|
||||||
e.email,
|
e.email,
|
||||||
new Doctrine\Tests\Models\CMS\CmsUserDTO(a.country, a.city, a.zip)
|
new Doctrine\Tests\Models\CMS\CmsUserDTO(
|
||||||
|
a.country,
|
||||||
|
a.city,
|
||||||
|
a.zip
|
||||||
|
)
|
||||||
)
|
)
|
||||||
FROM
|
FROM
|
||||||
Doctrine\Tests\Models\CMS\CmsUser u
|
Doctrine\Tests\Models\CMS\CmsUser u
|
||||||
|
Loading…
x
Reference in New Issue
Block a user