[2.0] Changed structure of creation of SqlWalkers in DQL Parser. They are now strings instead of instances of dummy classes. Implemented nesting level check for ResultVariable
This commit is contained in:
parent
e67b30703b
commit
462a27ee95
@ -109,12 +109,19 @@ class Parser
|
|||||||
*/
|
*/
|
||||||
private $_queryComponents = array();
|
private $_queryComponents = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keeps the nesting level of defined ResultVariables
|
||||||
|
*
|
||||||
|
* @var integer
|
||||||
|
*/
|
||||||
|
private $_nestingLevel = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tree walker chain
|
* Tree walker chain
|
||||||
*
|
*
|
||||||
* @var TreeWalker
|
* @var TreeWalker
|
||||||
*/
|
*/
|
||||||
private $_treeWalker;
|
private $_treeWalker = 'Doctrine\ORM\Query\SqlWalker';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new query parser object.
|
* Creates a new query parser object.
|
||||||
@ -132,7 +139,7 @@ class Parser
|
|||||||
/**
|
/**
|
||||||
* Sets the custom tree walker.
|
* Sets the custom tree walker.
|
||||||
*
|
*
|
||||||
* @param TreeWalker $treeWalker
|
* @param string $treeWalker
|
||||||
*/
|
*/
|
||||||
public function setTreeWalker($treeWalker)
|
public function setTreeWalker($treeWalker)
|
||||||
{
|
{
|
||||||
@ -257,7 +264,7 @@ class Parser
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create TreeWalker who creates the SQL from the AST
|
// Create TreeWalker who creates the SQL from the AST
|
||||||
$treeWalker = $this->_treeWalker ?: new SqlWalker(
|
$treeWalker = new $this->_treeWalker(
|
||||||
$this->_query, $this->_parserResult, $this->_queryComponents
|
$this->_query, $this->_parserResult, $this->_queryComponents
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -553,6 +560,7 @@ class Parser
|
|||||||
* It must exist in query components list.
|
* It must exist in query components list.
|
||||||
*
|
*
|
||||||
* @param string $identificationVariable
|
* @param string $identificationVariable
|
||||||
|
* @return array Query Component
|
||||||
*/
|
*/
|
||||||
private function _validateIdentificationVariable($identificationVariable)
|
private function _validateIdentificationVariable($identificationVariable)
|
||||||
{
|
{
|
||||||
@ -562,6 +570,8 @@ class Parser
|
|||||||
$identificationVariable . '\' in query components.'
|
$identificationVariable . '\' in query components.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->_queryComponents[$identificationVariable];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1091,6 +1101,9 @@ class Parser
|
|||||||
*/
|
*/
|
||||||
public function Subselect()
|
public function Subselect()
|
||||||
{
|
{
|
||||||
|
// Increase query nesting level
|
||||||
|
$this->_nestingLevel++;
|
||||||
|
|
||||||
$this->_beginDeferredPathExpressionStack();
|
$this->_beginDeferredPathExpressionStack();
|
||||||
$subselect = new AST\Subselect($this->SimpleSelectClause(), $this->SubselectFromClause());
|
$subselect = new AST\Subselect($this->SimpleSelectClause(), $this->SubselectFromClause());
|
||||||
$this->_processDeferredPathExpressionStack();
|
$this->_processDeferredPathExpressionStack();
|
||||||
@ -1111,6 +1124,9 @@ class Parser
|
|||||||
$this->_lexer->isNextToken(Lexer::T_ORDER) ? $this->OrderByClause() : null
|
$this->_lexer->isNextToken(Lexer::T_ORDER) ? $this->OrderByClause() : null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Decrease query nesting level
|
||||||
|
$this->_nestingLevel--;
|
||||||
|
|
||||||
return $subselect;
|
return $subselect;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1184,7 +1200,14 @@ class Parser
|
|||||||
$expr = $this->ResultVariable();
|
$expr = $this->ResultVariable();
|
||||||
|
|
||||||
// Check if ResultVariable is defined in query components
|
// Check if ResultVariable is defined in query components
|
||||||
$this->_validateIdentificationVariable($expr);
|
$queryComponent = $this->_validateIdentificationVariable($expr);
|
||||||
|
|
||||||
|
// ResultVariable exists in queryComponents, check nesting level
|
||||||
|
if ($queryComponent['nestingLevel'] != $this->_nestingLevel) {
|
||||||
|
$this->semanticalError(
|
||||||
|
"ResultVariable '$expr' is not in the same nesting level of its declaration"
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$expr = $this->StateFieldPathExpression();
|
$expr = $this->StateFieldPathExpression();
|
||||||
}
|
}
|
||||||
@ -1452,7 +1475,8 @@ class Parser
|
|||||||
|
|
||||||
// Include ResultVariable in query components.
|
// Include ResultVariable in query components.
|
||||||
$this->_queryComponents[$resultVariable] = array(
|
$this->_queryComponents[$resultVariable] = array(
|
||||||
'resultvariable' => $expression
|
'resultvariable' => $expression,
|
||||||
|
'nestingLevel' => $this->_nestingLevel,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1503,7 +1527,8 @@ class Parser
|
|||||||
|
|
||||||
// Include ResultVariable in query components.
|
// Include ResultVariable in query components.
|
||||||
$this->_queryComponents[$resultVariable] = array(
|
$this->_queryComponents[$resultVariable] = array(
|
||||||
'resultvariable' => $expr
|
'resultvariable' => $expr,
|
||||||
|
'nestingLevel' => $this->_nestingLevel,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user