From f83f5c3c8982fe05a3111409742973b9264e7f29 Mon Sep 17 00:00:00 2001 From: guilhermeblanco Date: Wed, 14 Jan 2009 04:59:35 +0000 Subject: [PATCH] [2.0] Code reorganization, preparing for battle. Fixes Strict error on EntityPersisterMock. --- .../ORM/Query/AST/SelectExpression.php | 60 +++++++++++++++++++ lib/Doctrine/ORM/Query/Parser.php | 8 ++- .../ORM/Query/Parser/AbstractSchemaName.php | 6 +- .../Parser/AliasIdentificationVariable.php | 4 +- .../ORM/Query/Parser/DeleteStatement.php | 6 +- .../Parser/FieldIdentificationVariable.php | 4 +- lib/Doctrine/ORM/Query/Parser/FromClause.php | 6 +- .../Query/Parser/IdentificationVariable.php | 4 +- .../IdentificationVariableDeclaration.php | 10 ++-- lib/Doctrine/ORM/Query/Parser/IndexBy.php | 6 +- lib/Doctrine/ORM/Query/Parser/Join.php | 8 +-- .../Query/Parser/JoinVariableDeclaration.php | 8 +-- .../ORM/Query/Parser/QueryLanguage.php | 8 +-- .../Query/Parser/RangeVariableDeclaration.php | 8 +-- .../ORM/Query/Parser/SelectClause.php | 10 ++-- .../ORM/Query/Parser/SelectExpression.php | 51 ++++++++++++---- .../ORM/Query/Parser/SelectStatement.php | 22 +++---- .../ORM/Query/Parser/SimpleStateField.php | 4 +- .../Parser/SimpleStateFieldPathExpression.php | 8 +-- .../ORM/Query/Parser/UpdateStatement.php | 6 +- ...erParamHolder.php => ParserDataHolder.php} | 2 +- lib/Doctrine/ORM/Query/ParserRule.php | 29 ++++++--- .../mocks/Doctrine_EntityPersisterMock.php | 4 +- 23 files changed, 193 insertions(+), 89 deletions(-) create mode 100644 lib/Doctrine/ORM/Query/AST/SelectExpression.php rename lib/Doctrine/ORM/Query/{ParserParamHolder.php => ParserDataHolder.php} (98%) diff --git a/lib/Doctrine/ORM/Query/AST/SelectExpression.php b/lib/Doctrine/ORM/Query/AST/SelectExpression.php new file mode 100644 index 000000000..93dea1444 --- /dev/null +++ b/lib/Doctrine/ORM/Query/AST/SelectExpression.php @@ -0,0 +1,60 @@ +. + */ + +/** + * SelectClause = "SELECT" ["DISTINCT"] SelectExpression {"," SelectExpression} + * + * @author Guilherme Blanco + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link http://www.phpdoctrine.org + * @since 2.0 + * @version $Revision$ + */ +class Doctrine_ORM_Query_AST_SelectExpression extends Doctrine_ORM_Query_AST +{ + protected $_expression; + + protected $_fieldIdentificationVariable; + + + /* Setters */ + public function setExpression($expression) + { + $this->_expression = $expression; + } + + public function setFieldIdentificationVariable($fieldIdentificationVariable) + { + $this->_fieldIdentificationVariable = $fieldIdentificationVariable; + } + + + /* Getters */ + public function getExpression() + { + return $this->_expression; + } + + public function getFieldIdentificationVariable() + { + return $this->_fieldIdentificationVariable; + } +} \ No newline at end of file diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 547ca0569..e844b882f 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -130,11 +130,13 @@ class Doctrine_ORM_Query_Parser $this->_scanner = new Doctrine_ORM_Query_Scanner($this->_input); $this->_sqlBuilder = new Doctrine_ORM_Query_SqlBuilder($this->_em); $this->_keywordTable = new Doctrine_ORM_Query_Token(); + + $defaultQueryComponent = Doctrine_ORM_Query_ParserRule::DEFAULT_QUERYCOMPONENT; $this->_parserResult = new Doctrine_ORM_Query_ParserResult( '', array( // queryComponent - 'dctrn' => array( + $defaultQueryComponent => array( 'metadata' => null, 'parent' => null, 'relation' => null, @@ -143,7 +145,7 @@ class Doctrine_ORM_Query_Parser ), ), array( // tableAliasMap - 'dctrn' => 'dctrn', + $defaultQueryComponent => $defaultQueryComponent, ) ); @@ -234,7 +236,7 @@ class Doctrine_ORM_Query_Parser // Building the Abstract Syntax Tree // We have to double the call of QueryLanguage to allow it to work correctly... =\ $DQL = new Doctrine_ORM_Query_Parser_QueryLanguage($this); - $AST = $DQL->parse('QueryLanguage', Doctrine_ORM_Query_ParserParamHolder::create()); + $AST = $DQL->parse('QueryLanguage'); // Check for end of string if ($this->lookahead !== null) { diff --git a/lib/Doctrine/ORM/Query/Parser/AbstractSchemaName.php b/lib/Doctrine/ORM/Query/Parser/AbstractSchemaName.php index 9ddc704dc..2297b1791 100644 --- a/lib/Doctrine/ORM/Query/Parser/AbstractSchemaName.php +++ b/lib/Doctrine/ORM/Query/Parser/AbstractSchemaName.php @@ -34,7 +34,7 @@ class Doctrine_ORM_Query_Parser_AbstractSchemaName extends Doctrine_ORM_Query_Pa protected $_AST = null; - public function syntax($paramHolder) + public function syntax() { // AbstractSchemaName ::= identifier $this->_AST = $this->AST('AbstractSchemaName'); @@ -44,7 +44,7 @@ class Doctrine_ORM_Query_Parser_AbstractSchemaName extends Doctrine_ORM_Query_Pa } - public function semantical($paramHolder) + public function semantical() { $componentName = $this->_AST->getComponentName(); @@ -62,6 +62,6 @@ class Doctrine_ORM_Query_Parser_AbstractSchemaName extends Doctrine_ORM_Query_Pa protected function _isDoctrineEntity($componentName) { - return class_exists($componentName)/* && is_subclass_of($componentName, 'Doctrine_ORM_Entity')*/; + return class_exists($componentName)/* && class_implements($componentName, 'Doctrine_ORM_Entity')*/; } } diff --git a/lib/Doctrine/ORM/Query/Parser/AliasIdentificationVariable.php b/lib/Doctrine/ORM/Query/Parser/AliasIdentificationVariable.php index b301e24f5..d315e7c47 100644 --- a/lib/Doctrine/ORM/Query/Parser/AliasIdentificationVariable.php +++ b/lib/Doctrine/ORM/Query/Parser/AliasIdentificationVariable.php @@ -34,7 +34,7 @@ class Doctrine_ORM_Query_Parser_AliasIdentificationVariable extends Doctrine_ORM protected $_AST = null; - public function syntax($paramHolder) + public function syntax() { // AliasIdentificationVariable = identifier $this->_AST = $this->AST('AliasIdentificationVariable'); @@ -44,7 +44,7 @@ class Doctrine_ORM_Query_Parser_AliasIdentificationVariable extends Doctrine_ORM } - public function semantical($paramHolder) + public function semantical() { $parserResult = $this->_parser->getParserResult(); diff --git a/lib/Doctrine/ORM/Query/Parser/DeleteStatement.php b/lib/Doctrine/ORM/Query/Parser/DeleteStatement.php index 46bb4820e..4ef4a4c21 100644 --- a/lib/Doctrine/ORM/Query/Parser/DeleteStatement.php +++ b/lib/Doctrine/ORM/Query/Parser/DeleteStatement.php @@ -34,15 +34,15 @@ class Doctrine_ORM_Query_Parser_DeleteStatement extends Doctrine_ORM_Query_Parse protected $_AST = null; - public function syntax($paramHolder) + public function syntax() { // DeleteStatement ::= DeleteClause [WhereClause] $this->_AST = $this->AST('DeleteStatement'); - $this->_AST->setDeleteClause($this->parse('DeleteClause', $paramHolder)); + $this->_AST->setDeleteClause($this->parse('DeleteClause')); if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_WHERE)) { - $this->_AST->setWhereClause($this->parse('WhereClause', $paramHolder)); + $this->_AST->setWhereClause($this->parse('WhereClause')); } // Return AST node diff --git a/lib/Doctrine/ORM/Query/Parser/FieldIdentificationVariable.php b/lib/Doctrine/ORM/Query/Parser/FieldIdentificationVariable.php index caabf5ec7..f8eabd734 100644 --- a/lib/Doctrine/ORM/Query/Parser/FieldIdentificationVariable.php +++ b/lib/Doctrine/ORM/Query/Parser/FieldIdentificationVariable.php @@ -34,7 +34,7 @@ class Doctrine_ORM_Query_Parser_FieldIdentificationVariable extends Doctrine_ORM protected $_AST = null; - public function syntax($paramHolder) + public function syntax() { // FieldIdentificationVariable ::= identifier $this->_AST = $this->AST('FieldIdentificationVariable'); @@ -47,7 +47,7 @@ class Doctrine_ORM_Query_Parser_FieldIdentificationVariable extends Doctrine_ORM } - public function semantical($paramHolder) + public function semantical() { $parserResult = $this->_parser->getParserResult(); diff --git a/lib/Doctrine/ORM/Query/Parser/FromClause.php b/lib/Doctrine/ORM/Query/Parser/FromClause.php index b83192115..62e273e84 100644 --- a/lib/Doctrine/ORM/Query/Parser/FromClause.php +++ b/lib/Doctrine/ORM/Query/Parser/FromClause.php @@ -34,7 +34,7 @@ class Doctrine_ORM_Query_Parser_FromClause extends Doctrine_ORM_Query_ParserRule protected $_AST = null; - public function syntax($paramHolder) + public function syntax() { // FromClause ::= "FROM" IdentificationVariableDeclaration {"," IdentificationVariableDeclaration} $this->_AST = $this->AST('FromClause'); @@ -42,14 +42,14 @@ class Doctrine_ORM_Query_Parser_FromClause extends Doctrine_ORM_Query_ParserRule $this->_parser->match(Doctrine_ORM_Query_Token::T_FROM); $this->_AST->addIdentificationVariableDeclaration( - $this->parse('IdentificationVariableDeclaration', $paramHolder) + $this->parse('IdentificationVariableDeclaration') ); while ($this->_isNextToken(',')) { $this->_parser->match(','); $this->_AST->addIdentificationVariableDeclaration( - $this->parse('IdentificationVariableDeclaration', $paramHolder) + $this->parse('IdentificationVariableDeclaration') ); } diff --git a/lib/Doctrine/ORM/Query/Parser/IdentificationVariable.php b/lib/Doctrine/ORM/Query/Parser/IdentificationVariable.php index 9919275e6..00a417570 100644 --- a/lib/Doctrine/ORM/Query/Parser/IdentificationVariable.php +++ b/lib/Doctrine/ORM/Query/Parser/IdentificationVariable.php @@ -34,7 +34,7 @@ class Doctrine_ORM_Query_Parser_IdentificationVariable extends Doctrine_ORM_Quer protected $_AST = null; - public function syntax($paramHolder) + public function syntax() { // IdentificationVariable ::= identifier $this->_AST = $this->AST('IdentificationVariable'); @@ -44,7 +44,7 @@ class Doctrine_ORM_Query_Parser_IdentificationVariable extends Doctrine_ORM_Quer } - public function semantical($paramHolder) + public function semantical() { $parserResult = $this->_parser->getParserResult(); diff --git a/lib/Doctrine/ORM/Query/Parser/IdentificationVariableDeclaration.php b/lib/Doctrine/ORM/Query/Parser/IdentificationVariableDeclaration.php index fc1231b15..58ff432af 100644 --- a/lib/Doctrine/ORM/Query/Parser/IdentificationVariableDeclaration.php +++ b/lib/Doctrine/ORM/Query/Parser/IdentificationVariableDeclaration.php @@ -34,15 +34,15 @@ class Doctrine_ORM_Query_Parser_IdentificationVariableDeclaration extends Doctri protected $_AST = null; - public function syntax($paramHolder) + public function syntax() { // IdentificationVariableDeclaration ::= RangeVariableDeclaration [IndexBy] {JoinVariableDeclaration}* $this->_AST = $this->AST('IdentificationVariableDeclaration'); - $this->_AST->setRangeVariableDeclaration($this->parse('RangeVariableDeclaration', $paramHolder)); + $this->_AST->setRangeVariableDeclaration($this->parse('RangeVariableDeclaration')); if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_INDEX)) { - $this->_AST->setIndexBy($this->parse('IndexBy', $paramHolder)); + $this->_AST->setIndexBy($this->parse('IndexBy')); } while ( @@ -50,12 +50,12 @@ class Doctrine_ORM_Query_Parser_IdentificationVariableDeclaration extends Doctri $this->_isNextToken(Doctrine_ORM_Query_Token::T_INNER) || $this->_isNextToken(Doctrine_ORM_Query_Token::T_JOIN) ) { - $this->_AST->addJoinVariableDeclaration($this->parse('JoinVariableDeclaration', $paramHolder)); + $this->_AST->addJoinVariableDeclaration($this->parse('JoinVariableDeclaration')); } } - public function semantical($paramHolder) + public function semantical() { // If we have an INDEX BY RangeVariableDeclaration if ($this->_AST->getIndexby() !== null) { diff --git a/lib/Doctrine/ORM/Query/Parser/IndexBy.php b/lib/Doctrine/ORM/Query/Parser/IndexBy.php index e5b2a58d4..4e08fd6ab 100644 --- a/lib/Doctrine/ORM/Query/Parser/IndexBy.php +++ b/lib/Doctrine/ORM/Query/Parser/IndexBy.php @@ -34,7 +34,7 @@ class Doctrine_ORM_Query_Parser_IndexBy extends Doctrine_ORM_Query_ParserRule protected $_AST = null; - public function syntax($paramHolder) + public function syntax() { // IndexBy ::= "INDEX" "BY" SimpleStateFieldPathExpression $this->_AST = $this->AST('IndexBy'); @@ -42,11 +42,11 @@ class Doctrine_ORM_Query_Parser_IndexBy extends Doctrine_ORM_Query_ParserRule $this->_parser->match(Doctrine_ORM_Query_Token::T_INDEX); $this->_parser->match(Doctrine_ORM_Query_Token::T_BY); - $this->_AST->setSimpleStateFieldPathExpression($this->parse('SimpleStateFieldPathExpression', $paramHolder)); + $this->_AST->setSimpleStateFieldPathExpression($this->parse('SimpleStateFieldPathExpression')); } - public function semantical($paramHolder) + public function semantical() { // Retrieving required information $parserResult = $this->_parser->getParserResult(); diff --git a/lib/Doctrine/ORM/Query/Parser/Join.php b/lib/Doctrine/ORM/Query/Parser/Join.php index d21646cd3..a3d8b227a 100644 --- a/lib/Doctrine/ORM/Query/Parser/Join.php +++ b/lib/Doctrine/ORM/Query/Parser/Join.php @@ -34,7 +34,7 @@ class Doctrine_ORM_Query_Parser_Join extends Doctrine_ORM_Query_ParserRule protected $_AST = null; - public function syntax($paramHolder) + public function syntax() { // Join ::= ["LEFT" ["OUTER"] | "INNER"] "JOIN" JoinAssociationPathExpression // ["AS"] AliasIdentificationVariable [("ON" | "WITH") ConditionalExpression] @@ -59,13 +59,13 @@ class Doctrine_ORM_Query_Parser_Join extends Doctrine_ORM_Query_ParserRule $this->_parser->match(Doctrine_ORM_Query_Token::T_JOIN); - $this->_AST->setJoinAssociationPathExpression($this->parse('JoinAssociationPathExpression', $paramHolder)); + $this->_AST->setJoinAssociationPathExpression($this->parse('JoinAssociationPathExpression')); if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_AS)) { $this->_parser->match(Doctrine_ORM_Query_Token::T_AS); } - $this->_AST->setAliasIdentificationVariable($this->parse('AliasIdentificationVariable', $paramHolder)); + $this->_AST->setAliasIdentificationVariable($this->parse('AliasIdentificationVariable')); // Check Join where type if ( @@ -82,7 +82,7 @@ class Doctrine_ORM_Query_Parser_Join extends Doctrine_ORM_Query_ParserRule $this->_parser->match(Doctrine_ORM_Query_Token::T_WITH); } - $this->_AST->setConditionalExpression($this->parse('ConditionalExpression', $paramHolder)); + $this->_AST->setConditionalExpression($this->parse('ConditionalExpression')); } // Return AST node diff --git a/lib/Doctrine/ORM/Query/Parser/JoinVariableDeclaration.php b/lib/Doctrine/ORM/Query/Parser/JoinVariableDeclaration.php index f9ec6e0bb..38eef8723 100644 --- a/lib/Doctrine/ORM/Query/Parser/JoinVariableDeclaration.php +++ b/lib/Doctrine/ORM/Query/Parser/JoinVariableDeclaration.php @@ -34,20 +34,20 @@ class Doctrine_ORM_Query_Parser_JoinVariableDeclaration extends Doctrine_ORM_Que protected $_AST = null; - public function syntax($paramHolder) + public function syntax() { // JoinVariableDeclaration ::= Join [IndexBy] $this->_AST = $this->AST('JoinVariableDeclaration'); - $this->_AST->setJoin($this->parse('Join', $paramHolder)); + $this->_AST->setJoin($this->parse('Join')); if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_INDEX)) { - $this->_AST->setIndexBy($this->parse('IndexBy', $paramHolder)); + $this->_AST->setIndexBy($this->parse('IndexBy')); } } - public function semantical($paramHolder) + public function semantical() { // If we have an INDEX BY JoinVariableDeclaration if ($this->_AST->getIndexby() !== null) { diff --git a/lib/Doctrine/ORM/Query/Parser/QueryLanguage.php b/lib/Doctrine/ORM/Query/Parser/QueryLanguage.php index ff08a30ff..c1312a456 100644 --- a/lib/Doctrine/ORM/Query/Parser/QueryLanguage.php +++ b/lib/Doctrine/ORM/Query/Parser/QueryLanguage.php @@ -33,20 +33,20 @@ */ class Doctrine_ORM_Query_Parser_QueryLanguage extends Doctrine_ORM_Query_ParserRule { - public function syntax($paramHolder) + public function syntax() { // QueryLanguage ::= SelectStatement | UpdateStatement | DeleteStatement switch ($this->_parser->lookahead['type']) { case Doctrine_ORM_Query_Token::T_SELECT: - return $this->parse('SelectStatement', $paramHolder); + return $this->parse('SelectStatement'); break; case Doctrine_ORM_Query_Token::T_UPDATE: - return $this->parse('UpdateStatement', $paramHolder); + return $this->parse('UpdateStatement'); break; case Doctrine_ORM_Query_Token::T_DELETE: - return $this->parse('DeleteStatement', $paramHolder); + return $this->parse('DeleteStatement'); break; default: diff --git a/lib/Doctrine/ORM/Query/Parser/RangeVariableDeclaration.php b/lib/Doctrine/ORM/Query/Parser/RangeVariableDeclaration.php index 58a85f1fa..669fc59cc 100644 --- a/lib/Doctrine/ORM/Query/Parser/RangeVariableDeclaration.php +++ b/lib/Doctrine/ORM/Query/Parser/RangeVariableDeclaration.php @@ -34,22 +34,22 @@ class Doctrine_ORM_Query_Parser_RangeVariableDeclaration extends Doctrine_ORM_Qu protected $_AST = null; - public function syntax($paramHolder) + public function syntax() { // RangeVariableDeclaration ::= AbstractSchemaName ["AS"] AliasIdentificationVariable $this->_AST = $this->AST('RangeVariableDeclaration'); - $this->_AST->setAbstractSchemaName($this->parse('AbstractSchemaName', $paramHolder)); + $this->_AST->setAbstractSchemaName($this->parse('AbstractSchemaName')); if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_AS)) { $this->_parser->match(Doctrine_ORM_Query_Token::T_AS); } - $this->_AST->setAliasIdentificationVariable($this->parse('AliasIdentificationVariable', $paramHolder)); + $this->_AST->setAliasIdentificationVariable($this->parse('AliasIdentificationVariable')); } - public function semantical($paramHolder) + public function semantical() { $parserResult = $this->_parser->getParserResult(); $componentName = $this->_AST->getAbstractSchemaName()->getComponentName(); diff --git a/lib/Doctrine/ORM/Query/Parser/SelectClause.php b/lib/Doctrine/ORM/Query/Parser/SelectClause.php index 65e8ee26f..8695d47c5 100644 --- a/lib/Doctrine/ORM/Query/Parser/SelectClause.php +++ b/lib/Doctrine/ORM/Query/Parser/SelectClause.php @@ -36,7 +36,7 @@ class Doctrine_ORM_Query_Parser_SelectClause extends Doctrine_ORM_Query_ParserRu protected $_selectExpressions = array(); - public function syntax($paramHolder) + public function syntax() { // SelectClause ::= "SELECT" ["DISTINCT"] SelectExpression {"," SelectExpression} $this->_AST = $this->AST('SelectClause'); @@ -51,21 +51,21 @@ class Doctrine_ORM_Query_Parser_SelectClause extends Doctrine_ORM_Query_ParserRu } // Process SelectExpressions (1..N) - $this->_selectExpressions[] = $this->parse('SelectExpression', $paramHolder); + $this->_selectExpressions[] = $this->parse('SelectExpression'); while ($this->_isNextToken(',')) { $this->_parser->match(','); - $this->_selectExpressions[] = $this->parse('SelectExpression', $paramHolder); + $this->_selectExpressions[] = $this->parse('SelectExpression'); } } - public function semantical($paramHolder) + public function semantical() { // We need to validate each SelectExpression for ($i = 0, $l = count($this->_selectExpressions); $i < $l; $i++) { - $this->_AST->addSelectExpression($this->_selectExpressions[$i]->semantical($paramHolder)); + $this->_AST->addSelectExpression($this->_selectExpressions[$i]->semantical()); } // Return AST node diff --git a/lib/Doctrine/ORM/Query/Parser/SelectExpression.php b/lib/Doctrine/ORM/Query/Parser/SelectExpression.php index 60fe7507a..67555dc7f 100644 --- a/lib/Doctrine/ORM/Query/Parser/SelectExpression.php +++ b/lib/Doctrine/ORM/Query/Parser/SelectExpression.php @@ -35,31 +35,60 @@ class Doctrine_ORM_Query_Parser_SelectExpression extends Doctrine_ORM_Query_Pars { protected $_AST = null; + protected $_expression = null; + + protected $_fieldIdentificationVariable = null; + - public function syntax($paramHolder) + public function syntax() { - // SelectExpression ::= IdentificationVariable ["." "*"] | - // (StateFieldPathExpression | AggregateExpression | "(" Subselect ")" ) - // [["AS"] FieldIdentificationVariable] - + // SelectExpression ::= IdentificationVariable ["." "*"] | StateFieldPathExpression | + // ( ( AggregateExpression | "(" Subselect ")" ) ["AS"] FieldIdentificationVariable ) + // First we recognize for an IdentificationVariable (Component alias) if ($this->_isIdentificationVariable()) { - $identificationVariable = $this->parse('IdentificationVariable', $paramHolder); - + $this->_expression = $this->parse('IdentificationVariable'); + // Inspecting if we are in a ["." "*"] if ($this->_isNextToken('.')) { $this->_parser->match('.'); $this->_parser->match('*'); } - - return $identificationVariable; + } else if ($this->_isFunction() || $this->_isSubselect()) { + $this->_expression = $this->parse( + $this->_isFunction() ? 'AggregateExpression' : 'Subselect' + ); + + if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_AS)) { + $this->_parser->match(Doctrine_ORM_Query_Token::T_AS); + } + + $this->_fieldIdentificationVariable = $this->parse('FieldIdentificationVariable'); + } else { + $this->_expression = $this->parse('StateFieldPathExpression'); } } + + + public function semantical() + { + $expression = $this->_expression->semantical(); + + if ($this->_fieldIdentificationVariable !== null) { + $expr = $expression; + + $expression = $this->AST('SelectExpression'); + $expression->setExpression($expr); + $expression->setFieldIdentificationVariable($this->_fieldIdentificationVariable->semantical()); + } + + return $expression; + } protected function _isIdentificationVariable() { - // Retrying to recoginize this grammar: IdentificationVariable ["." "*"] + // Trying to recoginize this grammar: IdentificationVariable ["." "*"] $token = $this->_parser->lookahead; $this->_parser->getScanner()->resetPeek(); @@ -70,7 +99,7 @@ class Doctrine_ORM_Query_Parser_SelectExpression extends Doctrine_ORM_Query_Pars // If we have a dot ".", then next char must be the "*" if ($token['value'] === '.') { $token = $this->_parser->getScanner()->peek(); - + return $token['value'] === '*'; } } diff --git a/lib/Doctrine/ORM/Query/Parser/SelectStatement.php b/lib/Doctrine/ORM/Query/Parser/SelectStatement.php index faf15464a..b3ffd084c 100644 --- a/lib/Doctrine/ORM/Query/Parser/SelectStatement.php +++ b/lib/Doctrine/ORM/Query/Parser/SelectStatement.php @@ -36,7 +36,7 @@ class Doctrine_ORM_Query_Parser_SelectStatement extends Doctrine_ORM_Query_Parse protected $_selectClause = null; - public function syntax($paramHolder) + public function syntax() { // SelectStatement ::= SelectClause FromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause] $this->_AST = $this->AST('SelectStatement'); @@ -44,36 +44,36 @@ class Doctrine_ORM_Query_Parser_SelectStatement extends Doctrine_ORM_Query_Parse // Disable the semantical check for SelectClause now. This is needed // since we dont know the query components yet (will be known only // when the FROM and WHERE clause are processed). - $paramHolder->set('semanticalCheck', false); - $this->_selectClause = $this->parse('SelectClause', $paramHolder); - $paramHolder->remove('semanticalCheck'); + $this->_dataHolder->set('semanticalCheck', false); + $this->_selectClause = $this->parse('SelectClause'); + $this->_dataHolder->remove('semanticalCheck'); - $this->_AST->setFromClause($this->parse('FromClause', $paramHolder)); + $this->_AST->setFromClause($this->parse('FromClause')); if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_WHERE)) { - $this->_AST->setWhereClause($this->parse('WhereClause', $paramHolder)); + $this->_AST->setWhereClause($this->parse('WhereClause')); } if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_GROUP)) { - $this->_AST->setGroupByClause($this->parse('GroupByClause', $paramHolder)); + $this->_AST->setGroupByClause($this->parse('GroupByClause')); } if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_HAVING)) { - $this->_AST->setHavingClause($this->parse('HavingClause', $paramHolder)); + $this->_AST->setHavingClause($this->parse('HavingClause')); } if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_ORDER)) { - $this->_AST->setOrderByClause($this->parse('OrderByClause', $paramHolder)); + $this->_AST->setOrderByClause($this->parse('OrderByClause')); } } - public function semantical($paramHolder) + public function semantical() { // We need to invoke the semantical check of SelectClause here, since // it was not yet checked. // The semantical checks will be forwarded to all SelectClause dependant grammar rules - $this->_AST->setSelectClause($this->_selectClause->semantical($paramHolder)); + $this->_AST->setSelectClause($this->_selectClause->semantical()); // Return AST node return $this->_AST; diff --git a/lib/Doctrine/ORM/Query/Parser/SimpleStateField.php b/lib/Doctrine/ORM/Query/Parser/SimpleStateField.php index c71337d64..ae1b6516c 100644 --- a/lib/Doctrine/ORM/Query/Parser/SimpleStateField.php +++ b/lib/Doctrine/ORM/Query/Parser/SimpleStateField.php @@ -34,9 +34,9 @@ class Doctrine_ORM_Query_Parser_SimpleStateField extends Doctrine_ORM_Query_Pars protected $_AST = null; - public function syntax($paramHolder) + public function syntax() { // SimpleStateField ::= FieldIdentificationVariable - return $this->parse('FieldIdentificationVariable', $paramHolder); + return $this->parse('FieldIdentificationVariable'); } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Query/Parser/SimpleStateFieldPathExpression.php b/lib/Doctrine/ORM/Query/Parser/SimpleStateFieldPathExpression.php index c56bbf0a1..94eae7232 100644 --- a/lib/Doctrine/ORM/Query/Parser/SimpleStateFieldPathExpression.php +++ b/lib/Doctrine/ORM/Query/Parser/SimpleStateFieldPathExpression.php @@ -34,20 +34,20 @@ class Doctrine_ORM_Query_Parser_SimpleStateFieldPathExpression extends Doctrine_ protected $_AST = null; - public function syntax($paramHolder) + public function syntax() { // SimpleStateFieldPathExpression ::= IdentificationVariable "." SimpleStateField $this->_AST = $this->AST('SimpleStateFieldPathExpression'); - $this->_AST->setIdentificationVariable($this->parse('IdentificationVariable', $paramHolder)); + $this->_AST->setIdentificationVariable($this->parse('IdentificationVariable')); $this->_parser->match('.'); - $this->_AST->setSimpleStateField($this->parse('SimpleStateField', $paramHolder)); + $this->_AST->setSimpleStateField($this->parse('SimpleStateField')); } - public function semantical($paramHolder) + public function semantical() { $parserResult = $this->_parser->getParserResult(); $componentAlias = $this->_AST->getIdentificationVariable()->getComponentAlias(); diff --git a/lib/Doctrine/ORM/Query/Parser/UpdateStatement.php b/lib/Doctrine/ORM/Query/Parser/UpdateStatement.php index 5b0cbbdd5..546e2597b 100644 --- a/lib/Doctrine/ORM/Query/Parser/UpdateStatement.php +++ b/lib/Doctrine/ORM/Query/Parser/UpdateStatement.php @@ -34,15 +34,15 @@ class Doctrine_ORM_Query_Parser_UpdateStatement extends Doctrine_ORM_Query_Parse protected $_AST = null; - public function syntax($paramHolder) + public function syntax() { // UpdateStatement ::= UpdateClause [WhereClause] $this->_AST = $this->AST('UpdateStatement'); - $this->_AST->setUpdateClause($this->parse('UpdateClause', $paramHolder)); + $this->_AST->setUpdateClause($this->parse('UpdateClause')); if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_WHERE)) { - $this->_AST->setWhereClause($this->parse('WhereClause', $paramHolder)); + $this->_AST->setWhereClause($this->parse('WhereClause')); } // Return AST node diff --git a/lib/Doctrine/ORM/Query/ParserParamHolder.php b/lib/Doctrine/ORM/Query/ParserDataHolder.php similarity index 98% rename from lib/Doctrine/ORM/Query/ParserParamHolder.php rename to lib/Doctrine/ORM/Query/ParserDataHolder.php index b4ec0d3a5..6eb80b71c 100644 --- a/lib/Doctrine/ORM/Query/ParserParamHolder.php +++ b/lib/Doctrine/ORM/Query/ParserDataHolder.php @@ -30,7 +30,7 @@ * @since 2.0 * @version $Revision$ */ -class Doctrine_ORM_Query_ParserParamHolder +class Doctrine_ORM_Query_ParserDataHolder { protected static $_instance; diff --git a/lib/Doctrine/ORM/Query/ParserRule.php b/lib/Doctrine/ORM/Query/ParserRule.php index cc8785e24..70960fea6 100644 --- a/lib/Doctrine/ORM/Query/ParserRule.php +++ b/lib/Doctrine/ORM/Query/ParserRule.php @@ -57,6 +57,13 @@ abstract class Doctrine_ORM_Query_ParserRule * @var EntityManager */ protected $_em; + + /** + * The Parser Data Holder. + * + * @var ParserDataHolder + */ + protected $_dataHolder; /** @@ -68,6 +75,7 @@ abstract class Doctrine_ORM_Query_ParserRule { $this->_parser = $parser; $this->_em = $this->_parser->getEntityManager(); + $this->_dataHolder = Doctrine_ORM_Query_ParserDataHolder::create(); } @@ -101,7 +109,7 @@ abstract class Doctrine_ORM_Query_ParserRule * @param array $paramHolder Production parameter holder * @return Doctrine_ORM_Query_ParserRule */ - public function parse($RuleName, $paramHolder) + public function parse($RuleName) { $BNFGrammarRule = $this->_getGrammarRule($RuleName); @@ -109,10 +117,10 @@ abstract class Doctrine_ORM_Query_ParserRule //echo "Params: " . var_export($paramHolder, true) . "\n"; // Syntax check - if ( ! $paramHolder->has('syntaxCheck') || $paramHolder->get('syntaxCheck') === true) { + if ( ! $this->_dataHolder->has('syntaxCheck') || $this->_dataHolder->get('syntaxCheck') === true) { //echo "Processing syntax checks of " . $RuleName . "...\n"; - $return = $BNFGrammarRule->syntax($paramHolder); + $return = $BNFGrammarRule->syntax(); if ($return !== null) { //echo "Returning Gramma Rule class: " . (is_object($return) ? get_class($return) : $return) . "...\n"; @@ -122,10 +130,10 @@ abstract class Doctrine_ORM_Query_ParserRule } // Semantical check - if ( ! $paramHolder->has('semanticalCheck') || $paramHolder->get('semanticalCheck') === true) { + if ( ! $this->_dataHolder->has('semanticalCheck') || $this->_dataHolder->get('semanticalCheck') === true) { //echo "Processing semantical checks of " . $RuleName . "...\n"; - $return = $BNFGrammarRule->semantical($paramHolder); + $return = $BNFGrammarRule->semantical(); if ($return !== null) { //echo "Returning Gramma Rule class: " . (is_object($return) ? get_class($return) : $return) . "...\n"; @@ -185,18 +193,23 @@ abstract class Doctrine_ORM_Query_ParserRule /** * @nodoc */ - abstract public function syntax($paramHolder); + abstract public function syntax(); /** * @nodoc */ - public function semantical($paramHolder) + public function semantical() { } - + public function getParser() { return $this->_parser; } + + public function getDataHolder() + { + return $this->_dataHolder; + } } diff --git a/tests/lib/mocks/Doctrine_EntityPersisterMock.php b/tests/lib/mocks/Doctrine_EntityPersisterMock.php index 47a65bd63..74aee4bf5 100644 --- a/tests/lib/mocks/Doctrine_EntityPersisterMock.php +++ b/tests/lib/mocks/Doctrine_EntityPersisterMock.php @@ -32,12 +32,12 @@ class Doctrine_EntityPersisterMock extends Doctrine_ORM_Persisters_StandardEntit $this->_mockIdGeneratorType = $genType; } - public function update(Doctrine_ORM_Entity $entity) + public function update($entity) { $this->_updates[] = $entity; } - public function delete(Doctrine_ORM_Entity $entity) + public function delete($entity) { $this->_deletes[] = $entity; }