From de93983dff875c898e953a660cae9ea4661cdaa1 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Sat, 11 Aug 2012 23:08:34 -0300 Subject: [PATCH] assume entity namespace when not given --- lib/Doctrine/ORM/Query/Parser.php | 776 ++++++++++-------- .../Tests/ORM/Functional/NewOperatorTest.php | 36 +- 2 files changed, 460 insertions(+), 352 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index a245afebb..22605a3e0 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -67,75 +67,96 @@ class Parser 'date_sub' => 'Doctrine\ORM\Query\AST\Functions\DateSubFunction', ); - /** + /* * Expressions that were encountered during parsing of identifiers and expressions * and still need to be validated. */ - private $_deferredIdentificationVariables = array(); - private $_deferredPartialObjectExpressions = array(); - private $_deferredPathExpressions = array(); - private $_deferredResultVariables = array(); + + /** + * @var array + */ + private $deferredIdentificationVariables = array(); + + /** + * @var array + */ + private $deferredPartialObjectExpressions = array(); + + /** + * @var array + */ + private $deferredPathExpressions = array(); + + /** + * @var array + */ + private $deferredResultVariables = array(); + + /** + * @var array + */ + private $deferredNewObjectExpressions = array(); /** * The lexer. * * @var \Doctrine\ORM\Query\Lexer */ - private $_lexer; + private $lexer; /** * The parser result. * * @var \Doctrine\ORM\Query\ParserResult */ - private $_parserResult; + private $parserResult; /** * The EntityManager. * * @var \Doctrine\ORM\EntityManager */ - private $_em; + private $em; /** * The Query to parse. * * @var Query */ - private $_query; + private $query; /** * Map of declared query components in the parsed query. * * @var array */ - private $_queryComponents = array(); + private $queryComponents = array(); /** * Keeps the nesting level of defined ResultVariables * * @var integer */ - private $_nestingLevel = 0; + private $nestingLevel = 0; /** * Any additional custom tree walkers that modify the AST. * * @var array */ - private $_customTreeWalkers = array(); + private $customTreeWalkers = array(); /** * The custom last tree walker, if any, that is responsible for producing the output. * * @var TreeWalker */ - private $_customOutputWalker; + private $customOutputWalker; /** * @var array */ - private $_identVariableExpressions = array(); + private $identVariableExpressions = array(); /** * Check if a function is internally defined. Used to prevent overwriting @@ -160,10 +181,10 @@ class Parser */ public function __construct(Query $query) { - $this->_query = $query; - $this->_em = $query->getEntityManager(); - $this->_lexer = new Lexer($query->getDql()); - $this->_parserResult = new ParserResult(); + $this->query = $query; + $this->em = $query->getEntityManager(); + $this->lexer = new Lexer($query->getDql()); + $this->parserResult = new ParserResult(); } /** @@ -174,7 +195,7 @@ class Parser */ public function setCustomOutputTreeWalker($className) { - $this->_customOutputWalker = $className; + $this->customOutputWalker = $className; } /** @@ -184,7 +205,7 @@ class Parser */ public function addCustomTreeWalker($className) { - $this->_customTreeWalkers[] = $className; + $this->customTreeWalkers[] = $className; } /** @@ -194,7 +215,7 @@ class Parser */ public function getLexer() { - return $this->_lexer; + return $this->lexer; } /** @@ -204,7 +225,7 @@ class Parser */ public function getParserResult() { - return $this->_parserResult; + return $this->parserResult; } /** @@ -214,7 +235,7 @@ class Parser */ public function getEntityManager() { - return $this->_em; + return $this->em; } /** @@ -231,21 +252,25 @@ class Parser // Process any deferred validations of some nodes in the AST. // This also allows post-processing of the AST for modification purposes. - $this->_processDeferredIdentificationVariables(); + $this->processDeferredIdentificationVariables(); - if ($this->_deferredPartialObjectExpressions) { - $this->_processDeferredPartialObjectExpressions(); + if ($this->deferredPartialObjectExpressions) { + $this->processDeferredPartialObjectExpressions(); } - if ($this->_deferredPathExpressions) { - $this->_processDeferredPathExpressions($AST); + if ($this->deferredPathExpressions) { + $this->processDeferredPathExpressions($AST); } - if ($this->_deferredResultVariables) { - $this->_processDeferredResultVariables(); + if ($this->deferredResultVariables) { + $this->processDeferredResultVariables(); } - $this->_processRootEntityAliasSelected(); + if ($this->deferredNewObjectExpressions) { + $this->processDeferredNewObjectExpressions($AST); + } + + $this->processRootEntityAliasSelected(); // TODO: Is there a way to remove this? It may impact the mixed hydration resultset a lot! $this->fixIdentificationVariableOrder($AST); @@ -265,14 +290,14 @@ class Parser */ public function match($token) { - $lookaheadType = $this->_lexer->lookahead['type']; + $lookaheadType = $this->lexer->lookahead['type']; // short-circuit on first condition, usually types match if ($lookaheadType !== $token && $token !== Lexer::T_IDENTIFIER && $lookaheadType <= Lexer::T_IDENTIFIER) { - $this->syntaxError($this->_lexer->getLiteral($token)); + $this->syntaxError($this->lexer->getLiteral($token)); } - $this->_lexer->moveNext(); + $this->lexer->moveNext(); } /** @@ -284,15 +309,15 @@ class Parser public function free($deep = false, $position = 0) { // WARNING! Use this method with care. It resets the scanner! - $this->_lexer->resetPosition($position); + $this->lexer->resetPosition($position); // Deep = true cleans peek and also any previously defined errors if ($deep) { - $this->_lexer->resetPeek(); + $this->lexer->resetPeek(); } - $this->_lexer->token = null; - $this->_lexer->lookahead = null; + $this->lexer->token = null; + $this->lexer->lookahead = null; } /** @@ -304,19 +329,19 @@ class Parser { $AST = $this->getAST(); - if (($customWalkers = $this->_query->getHint(Query::HINT_CUSTOM_TREE_WALKERS)) !== false) { - $this->_customTreeWalkers = $customWalkers; + if (($customWalkers = $this->query->getHint(Query::HINT_CUSTOM_TREE_WALKERS)) !== false) { + $this->customTreeWalkers = $customWalkers; } - if (($customOutputWalker = $this->_query->getHint(Query::HINT_CUSTOM_OUTPUT_WALKER)) !== false) { - $this->_customOutputWalker = $customOutputWalker; + if (($customOutputWalker = $this->query->getHint(Query::HINT_CUSTOM_OUTPUT_WALKER)) !== false) { + $this->customOutputWalker = $customOutputWalker; } // Run any custom tree walkers over the AST - if ($this->_customTreeWalkers) { - $treeWalkerChain = new TreeWalkerChain($this->_query, $this->_parserResult, $this->_queryComponents); + if ($this->customTreeWalkers) { + $treeWalkerChain = new TreeWalkerChain($this->query, $this->parserResult, $this->queryComponents); - foreach ($this->_customTreeWalkers as $walker) { + foreach ($this->customTreeWalkers as $walker) { $treeWalkerChain->addTreeWalker($walker); } @@ -335,13 +360,13 @@ class Parser } } - $outputWalkerClass = $this->_customOutputWalker ?: __NAMESPACE__ . '\SqlWalker'; - $outputWalker = new $outputWalkerClass($this->_query, $this->_parserResult, $this->_queryComponents); + $outputWalkerClass = $this->customOutputWalker ?: __NAMESPACE__ . '\SqlWalker'; + $outputWalker = new $outputWalkerClass($this->query, $this->parserResult, $this->queryComponents); // Assign an SQL executor to the parser result - $this->_parserResult->setSqlExecutor($outputWalker->getExecutor($AST)); + $this->parserResult->setSqlExecutor($outputWalker->getExecutor($AST)); - return $this->_parserResult; + return $this->parserResult; } /** @@ -356,16 +381,16 @@ class Parser */ private function fixIdentificationVariableOrder($AST) { - if (count($this->_identVariableExpressions) <= 1) { + if (count($this->identVariableExpressions) <= 1) { return; } - foreach ($this->_queryComponents as $dqlAlias => $qComp) { - if ( ! isset($this->_identVariableExpressions[$dqlAlias])) { + foreach ($this->queryComponents as $dqlAlias => $qComp) { + if ( ! isset($this->identVariableExpressions[$dqlAlias])) { continue; } - $expr = $this->_identVariableExpressions[$dqlAlias]; + $expr = $this->identVariableExpressions[$dqlAlias]; $key = array_search($expr, $AST->selectClause->selectExpressions); unset($AST->selectClause->selectExpressions[$key]); @@ -385,16 +410,16 @@ class Parser public function syntaxError($expected = '', $token = null) { if ($token === null) { - $token = $this->_lexer->lookahead; + $token = $this->lexer->lookahead; } $tokenPos = (isset($token['position'])) ? $token['position'] : '-1'; $message = "line 0, col {$tokenPos}: Error: "; $message .= ($expected !== '') ? "Expected {$expected}, got " : 'Unexpected '; - $message .= ($this->_lexer->lookahead === null) ? 'end of string.' : "'{$token['value']}'"; + $message .= ($this->lexer->lookahead === null) ? 'end of string.' : "'{$token['value']}'"; - throw QueryException::syntaxError($message, QueryException::dqlError($this->_query->getDQL())); + throw QueryException::syntaxError($message, QueryException::dqlError($this->query->getDQL())); } /** @@ -408,14 +433,14 @@ class Parser public function semanticalError($message = '', $token = null) { if ($token === null) { - $token = $this->_lexer->lookahead; + $token = $this->lexer->lookahead; } // Minimum exposed chars ahead of token $distance = 12; // Find a position of a final word to display in error string - $dql = $this->_query->getDql(); + $dql = $this->query->getDql(); $length = strlen($dql); $pos = $token['position'] + $distance; $pos = strpos($dql, ' ', ($length > $pos) ? $pos : $length); @@ -427,7 +452,7 @@ class Parser // Building informative message $message = 'line 0, col ' . $tokenPos . " near '" . $tokenStr . "': Error: " . $message; - throw QueryException::semanticalError($message, QueryException::dqlError($this->_query->getDQL())); + throw QueryException::semanticalError($message, QueryException::dqlError($this->query->getDQL())); } /** @@ -436,9 +461,9 @@ class Parser * @param boolean $resetPeek Reset peek after finding the closing parenthesis * @return array */ - private function _peekBeyondClosingParenthesis($resetPeek = true) + private function peekBeyondClosingParenthesis($resetPeek = true) { - $token = $this->_lexer->peek(); + $token = $this->lexer->peek(); $numUnmatched = 1; while ($numUnmatched > 0 && $token !== null) { @@ -455,11 +480,11 @@ class Parser // Do nothing } - $token = $this->_lexer->peek(); + $token = $this->lexer->peek(); } if ($resetPeek) { - $this->_lexer->resetPeek(); + $this->lexer->resetPeek(); } return $token; @@ -470,7 +495,7 @@ class Parser * * @return boolean TRUE if the token is a mathematical operator, FALSE otherwise. */ - private function _isMathOperator($token) + private function isMathOperator($token) { return in_array($token['type'], array(Lexer::T_PLUS, Lexer::T_MINUS, Lexer::T_DIVIDE, Lexer::T_MULTIPLY)); } @@ -480,12 +505,12 @@ class Parser * * @return boolean TRUE if the next-next tokens start a function, FALSE otherwise. */ - private function _isFunction() + private function isFunction() { - $peek = $this->_lexer->peek(); - $nextpeek = $this->_lexer->peek(); + $peek = $this->lexer->peek(); + $nextpeek = $this->lexer->peek(); - $this->_lexer->resetPeek(); + $this->lexer->resetPeek(); // We deny the COUNT(SELECT * FROM User u) here. COUNT won't be considered a function return ($peek['type'] === Lexer::T_OPEN_PARENTHESIS && $nextpeek['type'] !== Lexer::T_SELECT); @@ -496,7 +521,7 @@ class Parser * * @return boolean TRUE if the token type is an aggregate function, FALSE otherwise. */ - private function _isAggregateFunction($tokenType) + private function isAggregateFunction($tokenType) { return in_array($tokenType, array(Lexer::T_AVG, Lexer::T_MIN, Lexer::T_MAX, Lexer::T_SUM, Lexer::T_COUNT)); } @@ -506,9 +531,9 @@ class Parser * * @return boolean */ - private function _isNextAllAnySome() + private function isNextAllAnySome() { - return in_array($this->_lexer->lookahead['type'], array(Lexer::T_ALL, Lexer::T_ANY, Lexer::T_SOME)); + return in_array($this->lexer->lookahead['type'], array(Lexer::T_ALL, Lexer::T_ANY, Lexer::T_SOME)); } /** @@ -517,19 +542,19 @@ class Parser * * @return void */ - private function _processDeferredIdentificationVariables() + private function processDeferredIdentificationVariables() { - foreach ($this->_deferredIdentificationVariables as $deferredItem) { + foreach ($this->deferredIdentificationVariables as $deferredItem) { $identVariable = $deferredItem['expression']; // Check if IdentificationVariable exists in queryComponents - if ( ! isset($this->_queryComponents[$identVariable])) { + if ( ! isset($this->queryComponents[$identVariable])) { $this->semanticalError( "'$identVariable' is not defined.", $deferredItem['token'] ); } - $qComp = $this->_queryComponents[$identVariable]; + $qComp = $this->queryComponents[$identVariable]; // Check if queryComponent points to an AbstractSchemaName or a ResultVariable if ( ! isset($qComp['metadata'])) { @@ -547,17 +572,79 @@ class Parser } } + /** + * Validates that the given NewObjectExpression. + * + * @param \Doctrine\ORM\Query\AST\SelectClause $AST + * @return void + */ + private function processDeferredNewObjectExpressions($AST) + { + foreach ($this->deferredNewObjectExpressions as $deferredItem) { + $expression = $deferredItem['expression']; + $token = $deferredItem['token']; + $className = $expression->className; + $args = $expression->args; + + //first from item + if ( strpos($className, '\\') === false + && ! class_exists($className) + && isset($AST->fromClause + ->identificationVariableDeclarations[0] + ->rangeVariableDeclaration + ->abstractSchemaName)) { + + $fromClassName = $AST->fromClause + ->identificationVariableDeclarations[0] + ->rangeVariableDeclaration + ->abstractSchemaName; + + if (strpos($fromClassName, '\\') !== false) { + $fromClassName = substr($fromClassName, 0 , strrpos($fromClassName, '\\')); + $className = $fromClassName . '\\' . $className; + } + + if (class_exists($className)) { + $expression->className = $className; + } + } + + if ( ! class_exists($className)) { + $this->semanticalError(sprintf( + 'Class "%s" is not defined.', + $expression->className + ), $token); + } + + $class = new \ReflectionClass($className); + + if($class->getConstructor() === null) { + $this->semanticalError(sprintf( + 'Class "%s" has not a valid contructor.', + $className + ), $token); + } + + if($class->getConstructor()->getNumberOfRequiredParameters() > sizeof($args)) { + $this->semanticalError(sprintf( + 'Number of arguments does not match with "%s" constructor declaration.', + $className + ), $token); + } + } + } + /** * Validates that the given PartialObjectExpression is semantically correct. * It must exist in query components list. * * @return void */ - private function _processDeferredPartialObjectExpressions() + private function processDeferredPartialObjectExpressions() { - foreach ($this->_deferredPartialObjectExpressions as $deferredItem) { + foreach ($this->deferredPartialObjectExpressions as $deferredItem) { $expr = $deferredItem['expression']; - $class = $this->_queryComponents[$expr->identificationVariable]['metadata']; + $class = $this->queryComponents[$expr->identificationVariable]['metadata']; foreach ($expr->partialFieldSet as $field) { if (isset($class->fieldMappings[$field])) { @@ -584,19 +671,19 @@ class Parser * * @return void */ - private function _processDeferredResultVariables() + private function processDeferredResultVariables() { - foreach ($this->_deferredResultVariables as $deferredItem) { + foreach ($this->deferredResultVariables as $deferredItem) { $resultVariable = $deferredItem['expression']; // Check if ResultVariable exists in queryComponents - if ( ! isset($this->_queryComponents[$resultVariable])) { + if ( ! isset($this->queryComponents[$resultVariable])) { $this->semanticalError( "'$resultVariable' is not defined.", $deferredItem['token'] ); } - $qComp = $this->_queryComponents[$resultVariable]; + $qComp = $this->queryComponents[$resultVariable]; // Check if queryComponent points to an AbstractSchemaName or a ResultVariable if ( ! isset($qComp['resultVariable'])) { @@ -626,12 +713,12 @@ class Parser * @param array $deferredItem * @param mixed $AST */ - private function _processDeferredPathExpressions($AST) + private function processDeferredPathExpressions($AST) { - foreach ($this->_deferredPathExpressions as $deferredItem) { + foreach ($this->deferredPathExpressions as $deferredItem) { $pathExpression = $deferredItem['expression']; - $qComp = $this->_queryComponents[$pathExpression->identificationVariable]; + $qComp = $this->queryComponents[$pathExpression->identificationVariable]; $class = $qComp['metadata']; if (($field = $pathExpression->field) === null) { @@ -692,16 +779,16 @@ class Parser } } - private function _processRootEntityAliasSelected() + private function processRootEntityAliasSelected() { - if ( ! count($this->_identVariableExpressions)) { + if ( ! count($this->identVariableExpressions)) { return; } $foundRootEntity = false; - foreach ($this->_identVariableExpressions as $dqlAlias => $expr) { - if (isset($this->_queryComponents[$dqlAlias]) && $this->_queryComponents[$dqlAlias]['parent'] === null) { + foreach ($this->identVariableExpressions as $dqlAlias => $expr) { + if (isset($this->queryComponents[$dqlAlias]) && $this->queryComponents[$dqlAlias]['parent'] === null) { $foundRootEntity = true; } } @@ -720,9 +807,9 @@ class Parser */ public function QueryLanguage() { - $this->_lexer->moveNext(); + $this->lexer->moveNext(); - switch ($this->_lexer->lookahead['type']) { + switch ($this->lexer->lookahead['type']) { case Lexer::T_SELECT: $statement = $this->SelectStatement(); break; @@ -741,7 +828,7 @@ class Parser } // Check for end of string - if ($this->_lexer->lookahead !== null) { + if ($this->lexer->lookahead !== null) { $this->syntaxError('end of string'); } @@ -757,10 +844,10 @@ class Parser { $selectStatement = new AST\SelectStatement($this->SelectClause(), $this->FromClause()); - $selectStatement->whereClause = $this->_lexer->isNextToken(Lexer::T_WHERE) ? $this->WhereClause() : null; - $selectStatement->groupByClause = $this->_lexer->isNextToken(Lexer::T_GROUP) ? $this->GroupByClause() : null; - $selectStatement->havingClause = $this->_lexer->isNextToken(Lexer::T_HAVING) ? $this->HavingClause() : null; - $selectStatement->orderByClause = $this->_lexer->isNextToken(Lexer::T_ORDER) ? $this->OrderByClause() : null; + $selectStatement->whereClause = $this->lexer->isNextToken(Lexer::T_WHERE) ? $this->WhereClause() : null; + $selectStatement->groupByClause = $this->lexer->isNextToken(Lexer::T_GROUP) ? $this->GroupByClause() : null; + $selectStatement->havingClause = $this->lexer->isNextToken(Lexer::T_HAVING) ? $this->HavingClause() : null; + $selectStatement->orderByClause = $this->lexer->isNextToken(Lexer::T_ORDER) ? $this->OrderByClause() : null; return $selectStatement; } @@ -774,7 +861,7 @@ class Parser { $updateStatement = new AST\UpdateStatement($this->UpdateClause()); - $updateStatement->whereClause = $this->_lexer->isNextToken(Lexer::T_WHERE) ? $this->WhereClause() : null; + $updateStatement->whereClause = $this->lexer->isNextToken(Lexer::T_WHERE) ? $this->WhereClause() : null; return $updateStatement; } @@ -788,7 +875,7 @@ class Parser { $deleteStatement = new AST\DeleteStatement($this->DeleteClause()); - $deleteStatement->whereClause = $this->_lexer->isNextToken(Lexer::T_WHERE) ? $this->WhereClause() : null; + $deleteStatement->whereClause = $this->lexer->isNextToken(Lexer::T_WHERE) ? $this->WhereClause() : null; return $deleteStatement; } @@ -802,12 +889,12 @@ class Parser { $this->match(Lexer::T_IDENTIFIER); - $identVariable = $this->_lexer->token['value']; + $identVariable = $this->lexer->token['value']; - $this->_deferredIdentificationVariables[] = array( + $this->deferredIdentificationVariables[] = array( 'expression' => $identVariable, - 'nestingLevel' => $this->_nestingLevel, - 'token' => $this->_lexer->token, + 'nestingLevel' => $this->nestingLevel, + 'token' => $this->lexer->token, ); return $identVariable; @@ -822,11 +909,11 @@ class Parser { $this->match(Lexer::T_IDENTIFIER); - $aliasIdentVariable = $this->_lexer->token['value']; - $exists = isset($this->_queryComponents[$aliasIdentVariable]); + $aliasIdentVariable = $this->lexer->token['value']; + $exists = isset($this->queryComponents[$aliasIdentVariable]); if ($exists) { - $this->semanticalError("'$aliasIdentVariable' is already defined.", $this->_lexer->token); + $this->semanticalError("'$aliasIdentVariable' is already defined.", $this->lexer->token); } return $aliasIdentVariable; @@ -841,18 +928,18 @@ class Parser { $this->match(Lexer::T_IDENTIFIER); - $schemaName = ltrim($this->_lexer->token['value'], '\\'); + $schemaName = ltrim($this->lexer->token['value'], '\\'); if (strrpos($schemaName, ':') !== false) { list($namespaceAlias, $simpleClassName) = explode(':', $schemaName); - $schemaName = $this->_em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName; + $schemaName = $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName; } $exists = class_exists($schemaName, true); if ( ! $exists) { - $this->semanticalError("Class '$schemaName' is not defined.", $this->_lexer->token); + $this->semanticalError("Class '$schemaName' is not defined.", $this->lexer->token); } return $schemaName; @@ -867,11 +954,11 @@ class Parser { $this->match(Lexer::T_IDENTIFIER); - $resultVariable = $this->_lexer->token['value']; - $exists = isset($this->_queryComponents[$resultVariable]); + $resultVariable = $this->lexer->token['value']; + $exists = isset($this->queryComponents[$resultVariable]); if ($exists) { - $this->semanticalError("'$resultVariable' is already defined.", $this->_lexer->token); + $this->semanticalError("'$resultVariable' is already defined.", $this->lexer->token); } return $resultVariable; @@ -886,13 +973,13 @@ class Parser { $this->match(Lexer::T_IDENTIFIER); - $resultVariable = $this->_lexer->token['value']; + $resultVariable = $this->lexer->token['value']; // Defer ResultVariable validation - $this->_deferredResultVariables[] = array( + $this->deferredResultVariables[] = array( 'expression' => $resultVariable, - 'nestingLevel' => $this->_nestingLevel, - 'token' => $this->_lexer->token, + 'nestingLevel' => $this->nestingLevel, + 'token' => $this->lexer->token, ); return $resultVariable; @@ -907,7 +994,7 @@ class Parser { $identVariable = $this->IdentificationVariable(); - if ( ! isset($this->_queryComponents[$identVariable])) { + if ( ! isset($this->queryComponents[$identVariable])) { $this->semanticalError( 'Identification Variable ' . $identVariable .' used in join path expression but was not defined before.' ); @@ -916,10 +1003,10 @@ class Parser $this->match(Lexer::T_DOT); $this->match(Lexer::T_IDENTIFIER); - $field = $this->_lexer->token['value']; + $field = $this->lexer->token['value']; // Validate association field - $qComp = $this->_queryComponents[$identVariable]; + $qComp = $this->queryComponents[$identVariable]; $class = $qComp['metadata']; if ( ! $class->hasAssociation($field)) { @@ -943,21 +1030,21 @@ class Parser $identVariable = $this->IdentificationVariable(); $field = null; - if ($this->_lexer->isNextToken(Lexer::T_DOT)) { + if ($this->lexer->isNextToken(Lexer::T_DOT)) { $this->match(Lexer::T_DOT); $this->match(Lexer::T_IDENTIFIER); - $field = $this->_lexer->token['value']; + $field = $this->lexer->token['value']; } // Creating AST node $pathExpr = new AST\PathExpression($expectedTypes, $identVariable, $field); // Defer PathExpression validation if requested to be defered - $this->_deferredPathExpressions[] = array( + $this->deferredPathExpressions[] = array( 'expression' => $pathExpr, - 'nestingLevel' => $this->_nestingLevel, - 'token' => $this->_lexer->token, + 'nestingLevel' => $this->nestingLevel, + 'token' => $this->lexer->token, ); return $pathExpr; @@ -1030,7 +1117,7 @@ class Parser $this->match(Lexer::T_SELECT); // Check for DISTINCT - if ($this->_lexer->isNextToken(Lexer::T_DISTINCT)) { + if ($this->lexer->isNextToken(Lexer::T_DISTINCT)) { $this->match(Lexer::T_DISTINCT); $isDistinct = true; @@ -1040,7 +1127,7 @@ class Parser $selectExpressions = array(); $selectExpressions[] = $this->SelectExpression(); - while ($this->_lexer->isNextToken(Lexer::T_COMMA)) { + while ($this->lexer->isNextToken(Lexer::T_COMMA)) { $this->match(Lexer::T_COMMA); $selectExpressions[] = $this->SelectExpression(); @@ -1059,7 +1146,7 @@ class Parser $isDistinct = false; $this->match(Lexer::T_SELECT); - if ($this->_lexer->isNextToken(Lexer::T_DISTINCT)) { + if ($this->lexer->isNextToken(Lexer::T_DISTINCT)) { $this->match(Lexer::T_DISTINCT); $isDistinct = true; @@ -1076,16 +1163,16 @@ class Parser public function UpdateClause() { $this->match(Lexer::T_UPDATE); - $token = $this->_lexer->lookahead; + $token = $this->lexer->lookahead; $abstractSchemaName = $this->AbstractSchemaName(); - if ($this->_lexer->isNextToken(Lexer::T_AS)) { + if ($this->lexer->isNextToken(Lexer::T_AS)) { $this->match(Lexer::T_AS); } $aliasIdentificationVariable = $this->AliasIdentificationVariable(); - $class = $this->_em->getClassMetadata($abstractSchemaName); + $class = $this->em->getClassMetadata($abstractSchemaName); // Building queryComponent $queryComponent = array( @@ -1093,18 +1180,18 @@ class Parser 'parent' => null, 'relation' => null, 'map' => null, - 'nestingLevel' => $this->_nestingLevel, + 'nestingLevel' => $this->nestingLevel, 'token' => $token, ); - $this->_queryComponents[$aliasIdentificationVariable] = $queryComponent; + $this->queryComponents[$aliasIdentificationVariable] = $queryComponent; $this->match(Lexer::T_SET); $updateItems = array(); $updateItems[] = $this->UpdateItem(); - while ($this->_lexer->isNextToken(Lexer::T_COMMA)) { + while ($this->lexer->isNextToken(Lexer::T_COMMA)) { $this->match(Lexer::T_COMMA); $updateItems[] = $this->UpdateItem(); @@ -1125,21 +1212,21 @@ class Parser { $this->match(Lexer::T_DELETE); - if ($this->_lexer->isNextToken(Lexer::T_FROM)) { + if ($this->lexer->isNextToken(Lexer::T_FROM)) { $this->match(Lexer::T_FROM); } - $token = $this->_lexer->lookahead; + $token = $this->lexer->lookahead; $deleteClause = new AST\DeleteClause($this->AbstractSchemaName()); - if ($this->_lexer->isNextToken(Lexer::T_AS)) { + if ($this->lexer->isNextToken(Lexer::T_AS)) { $this->match(Lexer::T_AS); } $aliasIdentificationVariable = $this->AliasIdentificationVariable(); $deleteClause->aliasIdentificationVariable = $aliasIdentificationVariable; - $class = $this->_em->getClassMetadata($deleteClause->abstractSchemaName); + $class = $this->em->getClassMetadata($deleteClause->abstractSchemaName); // Building queryComponent $queryComponent = array( @@ -1147,11 +1234,11 @@ class Parser 'parent' => null, 'relation' => null, 'map' => null, - 'nestingLevel' => $this->_nestingLevel, + 'nestingLevel' => $this->nestingLevel, 'token' => $token, ); - $this->_queryComponents[$aliasIdentificationVariable] = $queryComponent; + $this->queryComponents[$aliasIdentificationVariable] = $queryComponent; return $deleteClause; } @@ -1168,7 +1255,7 @@ class Parser $identificationVariableDeclarations = array(); $identificationVariableDeclarations[] = $this->IdentificationVariableDeclaration(); - while ($this->_lexer->isNextToken(Lexer::T_COMMA)) { + while ($this->lexer->isNextToken(Lexer::T_COMMA)) { $this->match(Lexer::T_COMMA); $identificationVariableDeclarations[] = $this->IdentificationVariableDeclaration(); @@ -1189,7 +1276,7 @@ class Parser $identificationVariables = array(); $identificationVariables[] = $this->SubselectIdentificationVariableDeclaration(); - while ($this->_lexer->isNextToken(Lexer::T_COMMA)) { + while ($this->lexer->isNextToken(Lexer::T_COMMA)) { $this->match(Lexer::T_COMMA); $identificationVariables[] = $this->SubselectIdentificationVariableDeclaration(); @@ -1234,7 +1321,7 @@ class Parser $groupByItems = array($this->GroupByItem()); - while ($this->_lexer->isNextToken(Lexer::T_COMMA)) { + while ($this->lexer->isNextToken(Lexer::T_COMMA)) { $this->match(Lexer::T_COMMA); $groupByItems[] = $this->GroupByItem(); @@ -1256,7 +1343,7 @@ class Parser $orderByItems = array(); $orderByItems[] = $this->OrderByItem(); - while ($this->_lexer->isNextToken(Lexer::T_COMMA)) { + while ($this->lexer->isNextToken(Lexer::T_COMMA)) { $this->match(Lexer::T_COMMA); $orderByItems[] = $this->OrderByItem(); @@ -1273,17 +1360,17 @@ class Parser public function Subselect() { // Increase query nesting level - $this->_nestingLevel++; + $this->nestingLevel++; $subselect = new AST\Subselect($this->SimpleSelectClause(), $this->SubselectFromClause()); - $subselect->whereClause = $this->_lexer->isNextToken(Lexer::T_WHERE) ? $this->WhereClause() : null; - $subselect->groupByClause = $this->_lexer->isNextToken(Lexer::T_GROUP) ? $this->GroupByClause() : null; - $subselect->havingClause = $this->_lexer->isNextToken(Lexer::T_HAVING) ? $this->HavingClause() : null; - $subselect->orderByClause = $this->_lexer->isNextToken(Lexer::T_ORDER) ? $this->OrderByClause() : null; + $subselect->whereClause = $this->lexer->isNextToken(Lexer::T_WHERE) ? $this->WhereClause() : null; + $subselect->groupByClause = $this->lexer->isNextToken(Lexer::T_GROUP) ? $this->GroupByClause() : null; + $subselect->havingClause = $this->lexer->isNextToken(Lexer::T_HAVING) ? $this->HavingClause() : null; + $subselect->orderByClause = $this->lexer->isNextToken(Lexer::T_ORDER) ? $this->OrderByClause() : null; // Decrease query nesting level - $this->_nestingLevel--; + $this->nestingLevel--; return $subselect; } @@ -1312,20 +1399,20 @@ class Parser public function GroupByItem() { // We need to check if we are in a IdentificationVariable or SingleValuedPathExpression - $glimpse = $this->_lexer->glimpse(); + $glimpse = $this->lexer->glimpse(); if ($glimpse['type'] === Lexer::T_DOT) { return $this->SingleValuedPathExpression(); } // Still need to decide between IdentificationVariable or ResultVariable - $lookaheadValue = $this->_lexer->lookahead['value']; + $lookaheadValue = $this->lexer->lookahead['value']; - if ( ! isset($this->_queryComponents[$lookaheadValue])) { + if ( ! isset($this->queryComponents[$lookaheadValue])) { $this->semanticalError('Cannot group by undefined identification or result variable.'); } - return (isset($this->_queryComponents[$lookaheadValue]['metadata'])) + return (isset($this->queryComponents[$lookaheadValue]['metadata'])) ? $this->IdentificationVariable() : $this->ResultVariable(); } @@ -1341,15 +1428,15 @@ class Parser public function OrderByItem() { - $this->_lexer->peek(); // lookahead => '.' - $this->_lexer->peek(); // lookahead => token after '.' - $peek = $this->_lexer->peek(); // lookahead => token after the token after the '.' - $this->_lexer->resetPeek(); - $glimpse = $this->_lexer->glimpse(); + $this->lexer->peek(); // lookahead => '.' + $this->lexer->peek(); // lookahead => token after '.' + $peek = $this->lexer->peek(); // lookahead => token after the token after the '.' + $this->lexer->resetPeek(); + $glimpse = $this->lexer->glimpse(); switch (true) { - case ($this->_isMathOperator($peek)): + case ($this->isMathOperator($peek)): $expr = $this->SimpleArithmeticExpression(); break; @@ -1357,7 +1444,7 @@ class Parser $expr = $this->SingleValuedPathExpression(); break; - case ($this->_lexer->peek() && $this->_isMathOperator($this->_peekBeyondClosingParenthesis())): + case ($this->lexer->peek() && $this->isMathOperator($this->peekBeyondClosingParenthesis())): $expr = $this->ScalarExpression(); break; @@ -1371,12 +1458,12 @@ class Parser $item = new AST\OrderByItem($expr); switch (true) { - case ($this->_lexer->isNextToken(Lexer::T_DESC)): + case ($this->lexer->isNextToken(Lexer::T_DESC)): $this->match(Lexer::T_DESC); $type = 'DESC'; break; - case ($this->_lexer->isNextToken(Lexer::T_ASC)): + case ($this->lexer->isNextToken(Lexer::T_ASC)): $this->match(Lexer::T_ASC); break; @@ -1402,16 +1489,16 @@ class Parser */ public function NewValue() { - if ($this->_lexer->isNextToken(Lexer::T_NULL)) { + if ($this->lexer->isNextToken(Lexer::T_NULL)) { $this->match(Lexer::T_NULL); return null; } - if ($this->_lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) { + if ($this->lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) { $this->match(Lexer::T_INPUT_PARAMETER); - return new AST\InputParameter($this->_lexer->token['value']); + return new AST\InputParameter($this->lexer->token['value']); } return $this->SimpleArithmeticExpression(); @@ -1425,13 +1512,13 @@ class Parser public function IdentificationVariableDeclaration() { $rangeVariableDeclaration = $this->RangeVariableDeclaration(); - $indexBy = $this->_lexer->isNextToken(Lexer::T_INDEX) ? $this->IndexBy() : null; + $indexBy = $this->lexer->isNextToken(Lexer::T_INDEX) ? $this->IndexBy() : null; $joins = array(); while ( - $this->_lexer->isNextToken(Lexer::T_LEFT) || - $this->_lexer->isNextToken(Lexer::T_INNER) || - $this->_lexer->isNextToken(Lexer::T_JOIN) + $this->lexer->isNextToken(Lexer::T_LEFT) || + $this->lexer->isNextToken(Lexer::T_INNER) || + $this->lexer->isNextToken(Lexer::T_JOIN) ) { $joins[] = $this->Join(); } @@ -1449,7 +1536,7 @@ class Parser */ public function SubselectIdentificationVariableDeclaration() { - $this->_lexer->glimpse(); + $this->lexer->glimpse(); /* NOT YET IMPLEMENTED! @@ -1479,20 +1566,20 @@ class Parser $joinType = AST\Join::JOIN_TYPE_INNER; switch (true) { - case ($this->_lexer->isNextToken(Lexer::T_LEFT)): + case ($this->lexer->isNextToken(Lexer::T_LEFT)): $this->match(Lexer::T_LEFT); $joinType = AST\Join::JOIN_TYPE_LEFT; // Possible LEFT OUTER join - if ($this->_lexer->isNextToken(Lexer::T_OUTER)) { + if ($this->lexer->isNextToken(Lexer::T_OUTER)) { $this->match(Lexer::T_OUTER); $joinType = AST\Join::JOIN_TYPE_LEFTOUTER; } break; - case ($this->_lexer->isNextToken(Lexer::T_INNER)): + case ($this->lexer->isNextToken(Lexer::T_INNER)): $this->match(Lexer::T_INNER); break; @@ -1502,7 +1589,7 @@ class Parser $this->match(Lexer::T_JOIN); - $next = $this->_lexer->glimpse(); + $next = $this->lexer->glimpse(); $joinDeclaration = ($next['type'] === Lexer::T_DOT) ? $this->JoinAssociationDeclaration() : $this->RangeVariableDeclaration(); @@ -1511,7 +1598,7 @@ class Parser $join = new AST\Join($joinType, $joinDeclaration); // Check for ad-hoc Join conditions - if ($this->_lexer->isNextToken(Lexer::T_WITH) || $joinDeclaration instanceof AST\RangeVariableDeclaration) { + if ($this->lexer->isNextToken(Lexer::T_WITH) || $joinDeclaration instanceof AST\RangeVariableDeclaration) { $this->match(Lexer::T_WITH); $join->conditionalExpression = $this->ConditionalExpression(); @@ -1529,13 +1616,13 @@ class Parser { $abstractSchemaName = $this->AbstractSchemaName(); - if ($this->_lexer->isNextToken(Lexer::T_AS)) { + if ($this->lexer->isNextToken(Lexer::T_AS)) { $this->match(Lexer::T_AS); } - $token = $this->_lexer->lookahead; + $token = $this->lexer->lookahead; $aliasIdentificationVariable = $this->AliasIdentificationVariable(); - $classMetadata = $this->_em->getClassMetadata($abstractSchemaName); + $classMetadata = $this->em->getClassMetadata($abstractSchemaName); // Building queryComponent $queryComponent = array( @@ -1543,11 +1630,11 @@ class Parser 'parent' => null, 'relation' => null, 'map' => null, - 'nestingLevel' => $this->_nestingLevel, + 'nestingLevel' => $this->nestingLevel, 'token' => $token ); - $this->_queryComponents[$aliasIdentificationVariable] = $queryComponent; + $this->queryComponents[$aliasIdentificationVariable] = $queryComponent; return new AST\RangeVariableDeclaration($abstractSchemaName, $aliasIdentificationVariable); } @@ -1561,18 +1648,18 @@ class Parser { $joinAssociationPathExpression = $this->JoinAssociationPathExpression(); - if ($this->_lexer->isNextToken(Lexer::T_AS)) { + if ($this->lexer->isNextToken(Lexer::T_AS)) { $this->match(Lexer::T_AS); } $aliasIdentificationVariable = $this->AliasIdentificationVariable(); - $indexBy = $this->_lexer->isNextToken(Lexer::T_INDEX) ? $this->IndexBy() : null; + $indexBy = $this->lexer->isNextToken(Lexer::T_INDEX) ? $this->IndexBy() : null; $identificationVariable = $joinAssociationPathExpression->identificationVariable; $field = $joinAssociationPathExpression->associationField; - $class = $this->_queryComponents[$identificationVariable]['metadata']; - $targetClass = $this->_em->getClassMetadata($class->associationMappings[$field]['targetEntity']); + $class = $this->queryComponents[$identificationVariable]['metadata']; + $targetClass = $this->em->getClassMetadata($class->associationMappings[$field]['targetEntity']); // Building queryComponent $joinQueryComponent = array( @@ -1580,11 +1667,11 @@ class Parser 'parent' => $joinAssociationPathExpression->identificationVariable, 'relation' => $class->getAssociationMapping($field), 'map' => null, - 'nestingLevel' => $this->_nestingLevel, - 'token' => $this->_lexer->lookahead + 'nestingLevel' => $this->nestingLevel, + 'token' => $this->lexer->lookahead ); - $this->_queryComponents[$aliasIdentificationVariable] = $joinQueryComponent; + $this->queryComponents[$aliasIdentificationVariable] = $joinQueryComponent; return new AST\JoinAssociationDeclaration($joinAssociationPathExpression, $aliasIdentificationVariable, $indexBy); } @@ -1607,13 +1694,13 @@ class Parser $this->match(Lexer::T_OPEN_CURLY_BRACE); $this->match(Lexer::T_IDENTIFIER); - $partialFieldSet[] = $this->_lexer->token['value']; + $partialFieldSet[] = $this->lexer->token['value']; - while ($this->_lexer->isNextToken(Lexer::T_COMMA)) { + while ($this->lexer->isNextToken(Lexer::T_COMMA)) { $this->match(Lexer::T_COMMA); $this->match(Lexer::T_IDENTIFIER); - $partialFieldSet[] = $this->_lexer->token['value']; + $partialFieldSet[] = $this->lexer->token['value']; } $this->match(Lexer::T_CLOSE_CURLY_BRACE); @@ -1621,10 +1708,10 @@ class Parser $partialObjectExpression = new AST\PartialObjectExpression($identificationVariable, $partialFieldSet); // Defer PartialObjectExpression validation - $this->_deferredPartialObjectExpressions[] = array( + $this->deferredPartialObjectExpressions[] = array( 'expression' => $partialObjectExpression, - 'nestingLevel' => $this->_nestingLevel, - 'token' => $this->_lexer->token, + 'nestingLevel' => $this->nestingLevel, + 'token' => $this->lexer->token, ); return $partialObjectExpression; @@ -1639,21 +1726,13 @@ class Parser $this->match(Lexer::T_NEW); $this->match(Lexer::T_IDENTIFIER); - $className = $this->_lexer->token['value']; - - if ( ! class_exists($className, true)) { - $this->semanticalError("Class \"$className\" is not defined.", $this->_lexer->token); - } - - $class = new \ReflectionClass($className); - if($class->getConstructor() === null) { - $this->semanticalError("Class \"$className\" has not a valid contructor.", $this->_lexer->token); - } + $token = $this->lexer->token; + $className = $token['value']; $this->match(Lexer::T_OPEN_PARENTHESIS); $args[] = $this->NewObjectArg(); - while ($this->_lexer->isNextToken(Lexer::T_COMMA)) { + while ($this->lexer->isNextToken(Lexer::T_COMMA)) { $this->match(Lexer::T_COMMA); $args[] = $this->NewObjectArg(); @@ -1661,11 +1740,16 @@ class Parser $this->match(Lexer::T_CLOSE_PARENTHESIS); - if($class->getConstructor()->getNumberOfRequiredParameters() > sizeof($args)) { - $this->semanticalError("Number of arguments does not match.", $this->_lexer->token); - } + $expression = new AST\NewObjectExpression($className, $args); - return new AST\NewObjectExpression($className, $args);; + // Defer NewObjectExpression validation + $this->deferredNewObjectExpressions[] = array( + 'token' => $token, + 'expression' => $expression, + 'nestingLevel' => $this->nestingLevel, + ); + + return $expression; } /** @@ -1692,7 +1776,7 @@ class Parser $pathExpr = $this->StateFieldPathExpression(); // Add the INDEX BY info to the query component - $this->_queryComponents[$pathExpr->identificationVariable]['map'] = $pathExpr->field; + $this->queryComponents[$pathExpr->identificationVariable]['map'] = $pathExpr->field; return new AST\IndexBy($pathExpr); } @@ -1706,16 +1790,16 @@ class Parser */ public function ScalarExpression() { - $lookahead = $this->_lexer->lookahead['type']; + $lookahead = $this->lexer->lookahead['type']; switch ($lookahead) { case Lexer::T_IDENTIFIER: - $this->_lexer->peek(); // lookahead => '.' - $this->_lexer->peek(); // lookahead => token after '.' - $peek = $this->_lexer->peek(); // lookahead => token after the token after the '.' - $this->_lexer->resetPeek(); + $this->lexer->peek(); // lookahead => '.' + $this->lexer->peek(); // lookahead => token after '.' + $peek = $this->lexer->peek(); // lookahead => token after the token after the '.' + $this->lexer->resetPeek(); - if ($this->_isMathOperator($peek)) { + if ($this->isMathOperator($peek)) { return $this->SimpleArithmeticExpression(); } @@ -1732,7 +1816,7 @@ class Parser case Lexer::T_FALSE: $this->match($lookahead); - return new AST\Literal(AST\Literal::BOOLEAN, $this->_lexer->token['value']); + return new AST\Literal(AST\Literal::BOOLEAN, $this->lexer->token['value']); case Lexer::T_INPUT_PARAMETER: return $this->InputParameter(); @@ -1745,19 +1829,19 @@ class Parser return $this->CaseExpression(); default: - if ( ! ($this->_isFunction() || $this->_isAggregateFunction($lookahead))) { + if ( ! ($this->isFunction() || $this->isAggregateFunction($lookahead))) { $this->syntaxError(); } // We may be in an ArithmeticExpression (find the matching ")" and inspect for Math operator) - $this->_lexer->peek(); // "(" - $peek = $this->_peekBeyondClosingParenthesis(); + $this->lexer->peek(); // "(" + $peek = $this->peekBeyondClosingParenthesis(); - if ($this->_isMathOperator($peek)) { + if ($this->isMathOperator($peek)) { return $this->SimpleArithmeticExpression(); } - if ($this->_isAggregateFunction($this->_lexer->lookahead['type'])) { + if ($this->isAggregateFunction($this->lexer->lookahead['type'])) { return $this->AggregateExpression(); } @@ -1779,7 +1863,7 @@ class Parser */ public function CaseExpression() { - $lookahead = $this->_lexer->lookahead['type']; + $lookahead = $this->lexer->lookahead['type']; switch ($lookahead) { case Lexer::T_NULLIF: @@ -1789,8 +1873,8 @@ class Parser return $this->CoalesceExpression(); case Lexer::T_CASE: - $this->_lexer->resetPeek(); - $peek = $this->_lexer->peek(); + $this->lexer->resetPeek(); + $peek = $this->lexer->peek(); if ($peek['type'] === Lexer::T_WHEN) { return $this->GeneralCaseExpression(); @@ -1820,7 +1904,7 @@ class Parser $scalarExpressions = array(); $scalarExpressions[] = $this->ScalarExpression(); - while ($this->_lexer->isNextToken(Lexer::T_COMMA)) { + while ($this->lexer->isNextToken(Lexer::T_COMMA)) { $this->match(Lexer::T_COMMA); $scalarExpressions[] = $this->ScalarExpression(); @@ -1864,7 +1948,7 @@ class Parser do { $whenClauses[] = $this->WhenClause(); - } while ($this->_lexer->isNextToken(Lexer::T_WHEN)); + } while ($this->lexer->isNextToken(Lexer::T_WHEN)); $this->match(Lexer::T_ELSE); $scalarExpression = $this->ScalarExpression(); @@ -1887,7 +1971,7 @@ class Parser do { $simpleWhenClauses[] = $this->SimpleWhenClause(); - } while ($this->_lexer->isNextToken(Lexer::T_WHEN)); + } while ($this->lexer->isNextToken(Lexer::T_WHEN)); $this->match(Lexer::T_ELSE); $scalarExpression = $this->ScalarExpression(); @@ -1936,8 +2020,8 @@ class Parser { $expression = null; $identVariable = null; - $peek = $this->_lexer->glimpse(); - $lookaheadType = $this->_lexer->lookahead['type']; + $peek = $this->lexer->glimpse(); + $lookaheadType = $this->lexer->lookahead['type']; switch (true) { // ScalarExpression (u.name) @@ -1958,16 +2042,16 @@ class Parser break; // DQL Function (SUM(u.value) or SUM(u.value) + 1) - case ($this->_isFunction()): - $this->_lexer->peek(); // "(" + case ($this->isFunction()): + $this->lexer->peek(); // "(" switch (true) { - case ($this->_isMathOperator($this->_peekBeyondClosingParenthesis())): + case ($this->isMathOperator($this->peekBeyondClosingParenthesis())): // SUM(u.id) + COUNT(u.id) $expression = $this->ScalarExpression(); break; - case ($this->_isAggregateFunction($lookaheadType)): + case ($this->isAggregateFunction($lookaheadType)): // COUNT(u.id) $expression = $this->AggregateExpression(); break; @@ -2012,19 +2096,19 @@ class Parser default: $this->syntaxError( 'IdentificationVariable | ScalarExpression | AggregateExpression | FunctionDeclaration | PartialObjectExpression | "(" Subselect ")" | CaseExpression', - $this->_lexer->lookahead + $this->lexer->lookahead ); } // [["AS"] ["HIDDEN"] AliasResultVariable] - if ($this->_lexer->isNextToken(Lexer::T_AS)) { + if ($this->lexer->isNextToken(Lexer::T_AS)) { $this->match(Lexer::T_AS); } $hiddenAliasResultVariable = false; - if ($this->_lexer->isNextToken(Lexer::T_HIDDEN)) { + if ($this->lexer->isNextToken(Lexer::T_HIDDEN)) { $this->match(Lexer::T_HIDDEN); $hiddenAliasResultVariable = true; @@ -2032,14 +2116,14 @@ class Parser $aliasResultVariable = null; - if ($this->_lexer->isNextToken(Lexer::T_IDENTIFIER)) { - $token = $this->_lexer->lookahead; + if ($this->lexer->isNextToken(Lexer::T_IDENTIFIER)) { + $token = $this->lexer->lookahead; $aliasResultVariable = $this->AliasResultVariable(); // Include AliasResultVariable in query components. - $this->_queryComponents[$aliasResultVariable] = array( + $this->queryComponents[$aliasResultVariable] = array( 'resultVariable' => $expression, - 'nestingLevel' => $this->_nestingLevel, + 'nestingLevel' => $this->nestingLevel, 'token' => $token, ); } @@ -2049,7 +2133,7 @@ class Parser $expr = new AST\SelectExpression($expression, $aliasResultVariable, $hiddenAliasResultVariable); if ($identVariable) { - $this->_identVariableExpressions[$identVariable] = $expr; + $this->identVariableExpressions[$identVariable] = $expr; } return $expr; @@ -2065,9 +2149,9 @@ class Parser */ public function SimpleSelectExpression() { - $peek = $this->_lexer->glimpse(); + $peek = $this->lexer->glimpse(); - switch ($this->_lexer->lookahead['type']) { + switch ($this->lexer->lookahead['type']) { case Lexer::T_IDENTIFIER: switch (true) { case ($peek['type'] === Lexer::T_DOT): @@ -2080,13 +2164,13 @@ class Parser return new AST\SimpleSelectExpression($expression); - case ($this->_isFunction()): + case ($this->isFunction()): // SUM(u.id) + COUNT(u.id) - if ($this->_isMathOperator($this->_peekBeyondClosingParenthesis())) { + if ($this->isMathOperator($this->peekBeyondClosingParenthesis())) { return new AST\SimpleSelectExpression($this->ScalarExpression()); } // COUNT(u.id) - if ($this->_isAggregateFunction($this->_lexer->lookahead['type'])) { + if ($this->isAggregateFunction($this->lexer->lookahead['type'])) { return new AST\SimpleSelectExpression($this->AggregateExpression()); } // IDENTITY(u) @@ -2116,24 +2200,24 @@ class Parser // Do nothing } - $this->_lexer->peek(); + $this->lexer->peek(); $expression = $this->ScalarExpression(); $expr = new AST\SimpleSelectExpression($expression); - if ($this->_lexer->isNextToken(Lexer::T_AS)) { + if ($this->lexer->isNextToken(Lexer::T_AS)) { $this->match(Lexer::T_AS); } - if ($this->_lexer->isNextToken(Lexer::T_IDENTIFIER)) { - $token = $this->_lexer->lookahead; + if ($this->lexer->isNextToken(Lexer::T_IDENTIFIER)) { + $token = $this->lexer->lookahead; $resultVariable = $this->AliasResultVariable(); $expr->fieldIdentificationVariable = $resultVariable; // Include AliasResultVariable in query components. - $this->_queryComponents[$resultVariable] = array( + $this->queryComponents[$resultVariable] = array( 'resultvariable' => $expr, - 'nestingLevel' => $this->_nestingLevel, + 'nestingLevel' => $this->nestingLevel, 'token' => $token, ); } @@ -2151,7 +2235,7 @@ class Parser $conditionalTerms = array(); $conditionalTerms[] = $this->ConditionalTerm(); - while ($this->_lexer->isNextToken(Lexer::T_OR)) { + while ($this->lexer->isNextToken(Lexer::T_OR)) { $this->match(Lexer::T_OR); $conditionalTerms[] = $this->ConditionalTerm(); @@ -2176,7 +2260,7 @@ class Parser $conditionalFactors = array(); $conditionalFactors[] = $this->ConditionalFactor(); - while ($this->_lexer->isNextToken(Lexer::T_AND)) { + while ($this->lexer->isNextToken(Lexer::T_AND)) { $this->match(Lexer::T_AND); $conditionalFactors[] = $this->ConditionalFactor(); @@ -2200,7 +2284,7 @@ class Parser { $not = false; - if ($this->_lexer->isNextToken(Lexer::T_NOT)) { + if ($this->lexer->isNextToken(Lexer::T_NOT)) { $this->match(Lexer::T_NOT); $not = true; @@ -2229,18 +2313,18 @@ class Parser { $condPrimary = new AST\ConditionalPrimary; - if ( ! $this->_lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) { + if ( ! $this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) { $condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression(); return $condPrimary; } // Peek beyond the matching closing paranthesis ')' - $peek = $this->_peekBeyondClosingParenthesis(); + $peek = $this->peekBeyondClosingParenthesis(); if (in_array($peek['value'], array("=", "<", "<=", "<>", ">", ">=", "!=")) || in_array($peek['type'], array(Lexer::T_NOT, Lexer::T_BETWEEN, Lexer::T_LIKE, Lexer::T_IN, Lexer::T_IS, Lexer::T_EXISTS)) || - $this->_isMathOperator($peek)) { + $this->isMathOperator($peek)) { $condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression(); return $condPrimary; @@ -2262,54 +2346,54 @@ class Parser */ public function SimpleConditionalExpression() { - $token = $this->_lexer->lookahead; + $token = $this->lexer->lookahead; - if ($this->_lexer->isNextToken(Lexer::T_NOT)) { - $token = $this->_lexer->glimpse(); + if ($this->lexer->isNextToken(Lexer::T_NOT)) { + $token = $this->lexer->glimpse(); } if ($token['type'] === Lexer::T_EXISTS) { return $this->ExistsExpression(); } - $peek = $this->_lexer->glimpse(); + $peek = $this->lexer->glimpse(); if ($token['type'] === Lexer::T_IDENTIFIER || $token['type'] === Lexer::T_INPUT_PARAMETER) { if ($peek['value'] == '(') { // Peek beyond the matching closing paranthesis ')' - $this->_lexer->peek(); - $token = $this->_peekBeyondClosingParenthesis(false); + $this->lexer->peek(); + $token = $this->peekBeyondClosingParenthesis(false); if ($token['type'] === Lexer::T_NOT) { - $token = $this->_lexer->peek(); + $token = $this->lexer->peek(); } - $this->_lexer->resetPeek(); + $this->lexer->resetPeek(); } else { // Peek beyond the PathExpression (or InputParameter) - $peek = $this->_lexer->peek(); + $peek = $this->lexer->peek(); while ($peek['value'] === '.') { - $this->_lexer->peek(); - $peek = $this->_lexer->peek(); + $this->lexer->peek(); + $peek = $this->lexer->peek(); } // Also peek beyond a NOT if there is one if ($peek['type'] === Lexer::T_NOT) { - $peek = $this->_lexer->peek(); + $peek = $this->lexer->peek(); } $token = $peek; // We need to go even further in case of IS (differenciate between NULL and EMPTY) - $lookahead = $this->_lexer->peek(); + $lookahead = $this->lexer->peek(); // Also peek beyond a NOT if there is one if ($lookahead['type'] === Lexer::T_NOT) { - $lookahead = $this->_lexer->peek(); + $lookahead = $this->lexer->peek(); } - $this->_lexer->resetPeek(); + $this->lexer->resetPeek(); } } @@ -2346,7 +2430,7 @@ class Parser ); $this->match(Lexer::T_IS); - if ($this->_lexer->isNextToken(Lexer::T_NOT)) { + if ($this->lexer->isNextToken(Lexer::T_NOT)) { $this->match(Lexer::T_NOT); $emptyColletionCompExpr->not = true; } @@ -2369,7 +2453,7 @@ class Parser $not = false; $entityExpr = $this->EntityExpression(); - if ($this->_lexer->isNextToken(Lexer::T_NOT)) { + if ($this->lexer->isNextToken(Lexer::T_NOT)) { $this->match(Lexer::T_NOT); $not = true; @@ -2377,7 +2461,7 @@ class Parser $this->match(Lexer::T_MEMBER); - if ($this->_lexer->isNextToken(Lexer::T_OF)) { + if ($this->lexer->isNextToken(Lexer::T_OF)) { $this->match(Lexer::T_OF); } @@ -2396,24 +2480,24 @@ class Parser */ public function Literal() { - switch ($this->_lexer->lookahead['type']) { + switch ($this->lexer->lookahead['type']) { case Lexer::T_STRING: $this->match(Lexer::T_STRING); - return new AST\Literal(AST\Literal::STRING, $this->_lexer->token['value']); + return new AST\Literal(AST\Literal::STRING, $this->lexer->token['value']); case Lexer::T_INTEGER: case Lexer::T_FLOAT: $this->match( - $this->_lexer->isNextToken(Lexer::T_INTEGER) ? Lexer::T_INTEGER : Lexer::T_FLOAT + $this->lexer->isNextToken(Lexer::T_INTEGER) ? Lexer::T_INTEGER : Lexer::T_FLOAT ); - return new AST\Literal(AST\Literal::NUMERIC, $this->_lexer->token['value']); + return new AST\Literal(AST\Literal::NUMERIC, $this->lexer->token['value']); case Lexer::T_TRUE: case Lexer::T_FALSE: $this->match( - $this->_lexer->isNextToken(Lexer::T_TRUE) ? Lexer::T_TRUE : Lexer::T_FALSE + $this->lexer->isNextToken(Lexer::T_TRUE) ? Lexer::T_TRUE : Lexer::T_FALSE ); - return new AST\Literal(AST\Literal::BOOLEAN, $this->_lexer->token['value']); + return new AST\Literal(AST\Literal::BOOLEAN, $this->lexer->token['value']); default: $this->syntaxError('Literal'); @@ -2427,7 +2511,7 @@ class Parser */ public function InParameter() { - if ($this->_lexer->lookahead['type'] == Lexer::T_INPUT_PARAMETER) { + if ($this->lexer->lookahead['type'] == Lexer::T_INPUT_PARAMETER) { return $this->InputParameter(); } @@ -2443,7 +2527,7 @@ class Parser { $this->match(Lexer::T_INPUT_PARAMETER); - return new AST\InputParameter($this->_lexer->token['value']); + return new AST\InputParameter($this->lexer->token['value']); } /** @@ -2455,8 +2539,8 @@ class Parser { $expr = new AST\ArithmeticExpression; - if ($this->_lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) { - $peek = $this->_lexer->glimpse(); + if ($this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) { + $peek = $this->lexer->glimpse(); if ($peek['type'] === Lexer::T_SELECT) { $this->match(Lexer::T_OPEN_PARENTHESIS); @@ -2482,10 +2566,10 @@ class Parser $terms = array(); $terms[] = $this->ArithmeticTerm(); - while (($isPlus = $this->_lexer->isNextToken(Lexer::T_PLUS)) || $this->_lexer->isNextToken(Lexer::T_MINUS)) { + while (($isPlus = $this->lexer->isNextToken(Lexer::T_PLUS)) || $this->lexer->isNextToken(Lexer::T_MINUS)) { $this->match(($isPlus) ? Lexer::T_PLUS : Lexer::T_MINUS); - $terms[] = $this->_lexer->token['value']; + $terms[] = $this->lexer->token['value']; $terms[] = $this->ArithmeticTerm(); } @@ -2508,10 +2592,10 @@ class Parser $factors = array(); $factors[] = $this->ArithmeticFactor(); - while (($isMult = $this->_lexer->isNextToken(Lexer::T_MULTIPLY)) || $this->_lexer->isNextToken(Lexer::T_DIVIDE)) { + while (($isMult = $this->lexer->isNextToken(Lexer::T_MULTIPLY)) || $this->lexer->isNextToken(Lexer::T_DIVIDE)) { $this->match(($isMult) ? Lexer::T_MULTIPLY : Lexer::T_DIVIDE); - $factors[] = $this->_lexer->token['value']; + $factors[] = $this->lexer->token['value']; $factors[] = $this->ArithmeticFactor(); } @@ -2533,7 +2617,7 @@ class Parser { $sign = null; - if (($isPlus = $this->_lexer->isNextToken(Lexer::T_PLUS)) || $this->_lexer->isNextToken(Lexer::T_MINUS)) { + if (($isPlus = $this->lexer->isNextToken(Lexer::T_PLUS)) || $this->lexer->isNextToken(Lexer::T_MINUS)) { $this->match(($isPlus) ? Lexer::T_PLUS : Lexer::T_MINUS); $sign = $isPlus; } @@ -2557,7 +2641,7 @@ class Parser */ public function ArithmeticPrimary() { - if ($this->_lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) { + if ($this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) { $this->match(Lexer::T_OPEN_PARENTHESIS); $expr = $this->SimpleArithmeticExpression(); @@ -2566,14 +2650,14 @@ class Parser return $expr; } - switch ($this->_lexer->lookahead['type']) { + switch ($this->lexer->lookahead['type']) { case Lexer::T_COALESCE: case Lexer::T_NULLIF: case Lexer::T_CASE: return $this->CaseExpression(); case Lexer::T_IDENTIFIER: - $peek = $this->_lexer->glimpse(); + $peek = $this->lexer->glimpse(); if ($peek['value'] == '(') { return $this->FunctionDeclaration(); @@ -2583,7 +2667,7 @@ class Parser return $this->SingleValuedPathExpression(); } - if (isset($this->_queryComponents[$this->_lexer->lookahead['value']]['resultVariable'])) { + if (isset($this->queryComponents[$this->lexer->lookahead['value']]['resultVariable'])) { return $this->ResultVariable(); } @@ -2593,10 +2677,10 @@ class Parser return $this->InputParameter(); default: - $peek = $this->_lexer->glimpse(); + $peek = $this->lexer->glimpse(); if ($peek['value'] == '(') { - if ($this->_isAggregateFunction($this->_lexer->lookahead['type'])) { + if ($this->isAggregateFunction($this->lexer->lookahead['type'])) { return $this->AggregateExpression(); } @@ -2615,8 +2699,8 @@ class Parser */ public function StringExpression() { - if ($this->_lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) { - $peek = $this->_lexer->glimpse(); + if ($this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) { + $peek = $this->lexer->glimpse(); if ($peek['type'] === Lexer::T_SELECT) { $this->match(Lexer::T_OPEN_PARENTHESIS); @@ -2635,11 +2719,11 @@ class Parser */ public function StringPrimary() { - $lookaheadType = $this->_lexer->lookahead['type']; + $lookaheadType = $this->lexer->lookahead['type']; switch ($lookaheadType) { case Lexer::T_IDENTIFIER: - $peek = $this->_lexer->glimpse(); + $peek = $this->lexer->glimpse(); if ($peek['value'] == '.') { return $this->StateFieldPathExpression(); @@ -2656,7 +2740,7 @@ class Parser case Lexer::T_STRING: $this->match(Lexer::T_STRING); - return new AST\Literal(AST\Literal::STRING, $this->_lexer->token['value']); + return new AST\Literal(AST\Literal::STRING, $this->lexer->token['value']); case Lexer::T_INPUT_PARAMETER: return $this->InputParameter(); @@ -2667,7 +2751,7 @@ class Parser return $this->CaseExpression(); default: - if ($this->_isAggregateFunction($lookaheadType)) { + if ($this->isAggregateFunction($lookaheadType)) { return $this->AggregateExpression(); } } @@ -2685,9 +2769,9 @@ class Parser */ public function EntityExpression() { - $glimpse = $this->_lexer->glimpse(); + $glimpse = $this->lexer->glimpse(); - if ($this->_lexer->isNextToken(Lexer::T_IDENTIFIER) && $glimpse['value'] === '.') { + if ($this->lexer->isNextToken(Lexer::T_IDENTIFIER) && $glimpse['value'] === '.') { return $this->SingleValuedAssociationPathExpression(); } @@ -2701,7 +2785,7 @@ class Parser */ public function SimpleEntityExpression() { - if ($this->_lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) { + if ($this->lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) { return $this->InputParameter(); } @@ -2717,7 +2801,7 @@ class Parser */ public function AggregateExpression() { - $lookaheadType = $this->_lexer->lookahead['type']; + $lookaheadType = $this->lexer->lookahead['type']; $isDistinct = false; if ( ! in_array($lookaheadType, array(Lexer::T_COUNT, Lexer::T_AVG, Lexer::T_MAX, Lexer::T_MIN, Lexer::T_SUM))) { @@ -2725,10 +2809,10 @@ class Parser } $this->match($lookaheadType); - $functionName = $this->_lexer->token['value']; + $functionName = $this->lexer->token['value']; $this->match(Lexer::T_OPEN_PARENTHESIS); - if ($this->_lexer->isNextToken(Lexer::T_DISTINCT)) { + if ($this->lexer->isNextToken(Lexer::T_DISTINCT)) { $this->match(Lexer::T_DISTINCT); $isDistinct = true; } @@ -2749,8 +2833,8 @@ class Parser */ public function QuantifiedExpression() { - $lookaheadType = $this->_lexer->lookahead['type']; - $value = $this->_lexer->lookahead['value']; + $lookaheadType = $this->lexer->lookahead['type']; + $value = $this->lexer->lookahead['value']; if ( ! in_array($lookaheadType, array(Lexer::T_ALL, Lexer::T_ANY, Lexer::T_SOME))) { $this->syntaxError('ALL, ANY or SOME'); @@ -2777,7 +2861,7 @@ class Parser $not = false; $arithExpr1 = $this->ArithmeticExpression(); - if ($this->_lexer->isNextToken(Lexer::T_NOT)) { + if ($this->lexer->isNextToken(Lexer::T_NOT)) { $this->match(Lexer::T_NOT); $not = true; } @@ -2800,11 +2884,11 @@ class Parser */ public function ComparisonExpression() { - $this->_lexer->glimpse(); + $this->lexer->glimpse(); $leftExpr = $this->ArithmeticExpression(); $operator = $this->ComparisonOperator(); - $rightExpr = ($this->_isNextAllAnySome()) + $rightExpr = ($this->isNextAllAnySome()) ? $this->QuantifiedExpression() : $this->ArithmeticExpression(); @@ -2820,7 +2904,7 @@ class Parser { $inExpression = new AST\InExpression($this->ArithmeticExpression()); - if ($this->_lexer->isNextToken(Lexer::T_NOT)) { + if ($this->lexer->isNextToken(Lexer::T_NOT)) { $this->match(Lexer::T_NOT); $inExpression->not = true; } @@ -2828,13 +2912,13 @@ class Parser $this->match(Lexer::T_IN); $this->match(Lexer::T_OPEN_PARENTHESIS); - if ($this->_lexer->isNextToken(Lexer::T_SELECT)) { + if ($this->lexer->isNextToken(Lexer::T_SELECT)) { $inExpression->subselect = $this->Subselect(); } else { $literals = array(); $literals[] = $this->InParameter(); - while ($this->_lexer->isNextToken(Lexer::T_COMMA)) { + while ($this->lexer->isNextToken(Lexer::T_COMMA)) { $this->match(Lexer::T_COMMA); $literals[] = $this->InParameter(); } @@ -2856,7 +2940,7 @@ class Parser { $instanceOfExpression = new AST\InstanceOfExpression($this->IdentificationVariable()); - if ($this->_lexer->isNextToken(Lexer::T_NOT)) { + if ($this->lexer->isNextToken(Lexer::T_NOT)) { $this->match(Lexer::T_NOT); $instanceOfExpression->not = true; } @@ -2866,12 +2950,12 @@ class Parser $exprValues = array(); - if ($this->_lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) { + if ($this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) { $this->match(Lexer::T_OPEN_PARENTHESIS); $exprValues[] = $this->InstanceOfParameter(); - while ($this->_lexer->isNextToken(Lexer::T_COMMA)) { + while ($this->lexer->isNextToken(Lexer::T_COMMA)) { $this->match(Lexer::T_COMMA); $exprValues[] = $this->InstanceOfParameter(); @@ -2898,10 +2982,10 @@ class Parser */ public function InstanceOfParameter() { - if ($this->_lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) { + if ($this->lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) { $this->match(Lexer::T_INPUT_PARAMETER); - return new AST\InputParameter($this->_lexer->token['value']); + return new AST\InputParameter($this->lexer->token['value']); } return $this->AliasIdentificationVariable(); @@ -2917,27 +3001,27 @@ class Parser $stringExpr = $this->StringExpression(); $not = false; - if ($this->_lexer->isNextToken(Lexer::T_NOT)) { + if ($this->lexer->isNextToken(Lexer::T_NOT)) { $this->match(Lexer::T_NOT); $not = true; } $this->match(Lexer::T_LIKE); - if ($this->_lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) { + if ($this->lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) { $this->match(Lexer::T_INPUT_PARAMETER); - $stringPattern = new AST\InputParameter($this->_lexer->token['value']); + $stringPattern = new AST\InputParameter($this->lexer->token['value']); } else { $stringPattern = $this->StringPrimary(); } $escapeChar = null; - if ($this->_lexer->lookahead['type'] === Lexer::T_ESCAPE) { + if ($this->lexer->lookahead['type'] === Lexer::T_ESCAPE) { $this->match(Lexer::T_ESCAPE); $this->match(Lexer::T_STRING); - $escapeChar = new AST\Literal(AST\Literal::STRING, $this->_lexer->token['value']); + $escapeChar = new AST\Literal(AST\Literal::STRING, $this->lexer->token['value']); } $likeExpr = new AST\LikeExpression($stringExpr, $stringPattern, $escapeChar); @@ -2953,9 +3037,9 @@ class Parser */ public function NullComparisonExpression() { - if ($this->_lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) { + if ($this->lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) { $this->match(Lexer::T_INPUT_PARAMETER); - $expr = new AST\InputParameter($this->_lexer->token['value']); + $expr = new AST\InputParameter($this->lexer->token['value']); } else { $expr = $this->SingleValuedPathExpression(); } @@ -2963,7 +3047,7 @@ class Parser $nullCompExpr = new AST\NullComparisonExpression($expr); $this->match(Lexer::T_IS); - if ($this->_lexer->isNextToken(Lexer::T_NOT)) { + if ($this->lexer->isNextToken(Lexer::T_NOT)) { $this->match(Lexer::T_NOT); $nullCompExpr->not = true; } @@ -2982,7 +3066,7 @@ class Parser { $not = false; - if ($this->_lexer->isNextToken(Lexer::T_NOT)) { + if ($this->lexer->isNextToken(Lexer::T_NOT)) { $this->match(Lexer::T_NOT); $not = true; } @@ -3005,7 +3089,7 @@ class Parser */ public function ComparisonOperator() { - switch ($this->_lexer->lookahead['value']) { + switch ($this->lexer->lookahead['value']) { case '=': $this->match(Lexer::T_EQUALS); @@ -3015,10 +3099,10 @@ class Parser $this->match(Lexer::T_LOWER_THAN); $operator = '<'; - if ($this->_lexer->isNextToken(Lexer::T_EQUALS)) { + if ($this->lexer->isNextToken(Lexer::T_EQUALS)) { $this->match(Lexer::T_EQUALS); $operator .= '='; - } else if ($this->_lexer->isNextToken(Lexer::T_GREATER_THAN)) { + } else if ($this->lexer->isNextToken(Lexer::T_GREATER_THAN)) { $this->match(Lexer::T_GREATER_THAN); $operator .= '>'; } @@ -3029,7 +3113,7 @@ class Parser $this->match(Lexer::T_GREATER_THAN); $operator = '>'; - if ($this->_lexer->isNextToken(Lexer::T_EQUALS)) { + if ($this->lexer->isNextToken(Lexer::T_EQUALS)) { $this->match(Lexer::T_EQUALS); $operator .= '='; } @@ -3052,7 +3136,7 @@ class Parser */ public function FunctionDeclaration() { - $token = $this->_lexer->lookahead; + $token = $this->lexer->lookahead; $funcName = strtolower($token['value']); // Check for built-in functions first! @@ -3076,11 +3160,11 @@ class Parser */ private function CustomFunctionDeclaration() { - $token = $this->_lexer->lookahead; + $token = $this->lexer->lookahead; $funcName = strtolower($token['value']); // Check for custom functions afterwards - $config = $this->_em->getConfiguration(); + $config = $this->em->getConfiguration(); switch (true) { case ($config->getCustomStringFunction($funcName) !== null): @@ -3108,7 +3192,7 @@ class Parser */ public function FunctionsReturningNumerics() { - $funcNameLower = strtolower($this->_lexer->lookahead['value']); + $funcNameLower = strtolower($this->lexer->lookahead['value']); $funcClass = self::$_NUMERIC_FUNCTIONS[$funcNameLower]; $function = new $funcClass($funcNameLower); @@ -3120,8 +3204,8 @@ class Parser public function CustomFunctionsReturningNumerics() { // getCustomNumericFunction is case-insensitive - $funcName = strtolower($this->_lexer->lookahead['value']); - $funcClass = $this->_em->getConfiguration()->getCustomNumericFunction($funcName); + $funcName = strtolower($this->lexer->lookahead['value']); + $funcClass = $this->em->getConfiguration()->getCustomNumericFunction($funcName); $function = new $funcClass($funcName); $function->parse($this); @@ -3134,7 +3218,7 @@ class Parser */ public function FunctionsReturningDatetime() { - $funcNameLower = strtolower($this->_lexer->lookahead['value']); + $funcNameLower = strtolower($this->lexer->lookahead['value']); $funcClass = self::$_DATETIME_FUNCTIONS[$funcNameLower]; $function = new $funcClass($funcNameLower); @@ -3146,8 +3230,8 @@ class Parser public function CustomFunctionsReturningDatetime() { // getCustomDatetimeFunction is case-insensitive - $funcName = $this->_lexer->lookahead['value']; - $funcClass = $this->_em->getConfiguration()->getCustomDatetimeFunction($funcName); + $funcName = $this->lexer->lookahead['value']; + $funcClass = $this->em->getConfiguration()->getCustomDatetimeFunction($funcName); $function = new $funcClass($funcName); $function->parse($this); @@ -3165,7 +3249,7 @@ class Parser */ public function FunctionsReturningStrings() { - $funcNameLower = strtolower($this->_lexer->lookahead['value']); + $funcNameLower = strtolower($this->lexer->lookahead['value']); $funcClass = self::$_STRING_FUNCTIONS[$funcNameLower]; $function = new $funcClass($funcNameLower); @@ -3177,8 +3261,8 @@ class Parser public function CustomFunctionsReturningStrings() { // getCustomStringFunction is case-insensitive - $funcName = $this->_lexer->lookahead['value']; - $funcClass = $this->_em->getConfiguration()->getCustomStringFunction($funcName); + $funcName = $this->lexer->lookahead['value']; + $funcClass = $this->em->getConfiguration()->getCustomStringFunction($funcName); $function = new $funcClass($funcName); $function->parse($this); diff --git a/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php b/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php index 2109482fa..cb340912b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php @@ -98,7 +98,7 @@ class NewOperatorTest extends \Doctrine\Tests\OrmFunctionalTestCase e.email, a.city ) - FROM + FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.email e @@ -119,16 +119,40 @@ class NewOperatorTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals($this->fixtures[0]->name, $result[0]->name); $this->assertEquals($this->fixtures[1]->name, $result[1]->name); $this->assertEquals($this->fixtures[2]->name, $result[2]->name); - + $this->assertEquals($this->fixtures[0]->email->email, $result[0]->email); $this->assertEquals($this->fixtures[1]->email->email, $result[1]->email); $this->assertEquals($this->fixtures[2]->email->email, $result[2]->email); - + $this->assertEquals($this->fixtures[0]->address->city, $result[0]->address); $this->assertEquals($this->fixtures[1]->address->city, $result[1]->address); $this->assertEquals($this->fixtures[2]->address->city, $result[2]->address); } + public function testShouldAssumeFromEntityNamespaceWhenNotGiven() + { + $dql = " + SELECT + new CmsUserDTO(u.name, e.email, a.city) + FROM + Doctrine\Tests\Models\CMS\CmsUser u + JOIN + u.email e + JOIN + u.address a + ORDER BY + u.name"; + + $query = $this->_em->createQuery($dql); + $result = $query->getResult(); + + $this->assertCount(3, $result); + + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]); + } + public function testShouldSupportLiteralExpression() { $dql = " @@ -403,11 +427,11 @@ class NewOperatorTest extends \Doctrine\Tests\OrmFunctionalTestCase { $dql = " SELECT - new Doctrine\Tests\Models\CMS\CmsUserDTO( + new CmsUserDTO( u.name, e.email ), - new Doctrine\Tests\Models\CMS\CmsAddressDTO( + new CmsAddressDTO( a.country, a.city ) @@ -473,7 +497,7 @@ class NewOperatorTest extends \Doctrine\Tests\OrmFunctionalTestCase /** * @expectedException Doctrine\ORM\Query\QueryException - * @expectedExceptionMessage [Semantical Error] line 0, col 68 near ') FROM Doctrine\Tests\Models\CMS\CmsUser': Error: Number of arguments does not match. + * @expectedExceptionMessage [Semantical Error] line 0, col 11 near 'Doctrine\Tests\ORM\Functional\ClassWithTooMuchArgs(u.name)': Error: Number of arguments does not match with "Doctrine\Tests\ORM\Functional\ClassWithTooMuchArgs" constructor declaration. */ public function testInvalidClassWithoutConstructorException() {