Parses a DQL query, reports any errors in it, and generates an AST.
Since: 2.0
Author: Guilherme Blanco (guilhermeblanco@hotmail.com)
Author: Jonathan Wage (jonwage@gmail.com)
Author: Roman Borschel (roman@code-factory.org)
Author: Janne Vanhala (jpvanhal@cc.hut.fi)
Ejemplo n.º 1
0
 public function parse(Query\Parser $parser)
 {
     $parser->match(Query\Lexer::T_IDENTIFIER);
     $parser->match(Query\Lexer::T_OPEN_PARENTHESIS);
     $this->arg = $parser->ArithmeticPrimary();
     $parser->match(Query\Lexer::T_CLOSE_PARENTHESIS);
 }
Ejemplo n.º 2
0
 public function parse(\Doctrine\ORM\Query\Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->arithmeticExpression = $parser->SimpleArithmeticExpression();
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
 /**
  * {@inheritdoc}
  */
 public function parse(Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->stringPrimary = $parser->StringPrimary();
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Ejemplo n.º 4
0
 /**
  * @override
  */
 public function parse(\Doctrine\ORM\Query\Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->pathExpression = $parser->SingleValuedAssociationPathExpression();
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Ejemplo n.º 5
0
 public function parse(\Doctrine\ORM\Query\Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->stringExpression = $parser->StringPrimary();
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Ejemplo n.º 6
0
 public function parse(\Doctrine\ORM\Query\Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->date = $parser->ArithmeticPrimary();
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Ejemplo n.º 7
0
 public function parse(Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->dateExpression = $parser->ArithmeticPrimary();
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function parse(Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->parameters[self::PARAMETER_KEY] = $parser->SimpleArithmeticExpression();
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Ejemplo n.º 9
0
 public function parse(Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->value = $parser->SimpleArithmeticExpression();
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Ejemplo n.º 10
0
 /**
  * @override
  */
 public function parse(\Doctrine\ORM\Query\Parser $parser)
 {
     $lexer = $parser->getLexer();
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Ejemplo n.º 11
0
 public function parse(Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->expressions[] = $parser->ArithmeticFactor();
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function parse(Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->pathExpression = $parser->SingleValuedPathExpression();
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Ejemplo n.º 13
0
 public function parse(\Doctrine\ORM\Query\Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     //$this->datePart=$parser->StringPrimary();
     $this->dateField = $parser->StateFieldPathExpression();
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Ejemplo n.º 14
0
 public function parse(\Doctrine\ORM\Query\Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     // (2)
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     // (3)
     $this->var1 = $parser->ConditionalExpression();
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
     // (3)
 }
Ejemplo n.º 15
0
 public function parse(Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     // (2)
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     // (3)
     $this->dateExpression = $parser->ArithmeticExpression();
     // (4)
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
     // (3)
 }
 public function parse(\Doctrine\ORM\Query\Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     // (2)
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     // (3)
     $this->expression = $parser->ArithmeticPrimary();
     // (4)
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
     // (3)
 }
 /**
  * @inheritdoc
  */
 public function parse(\Doctrine\ORM\Query\Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     // 'DATE'
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     // '('
     $this->date = $parser->ArithmeticPrimary();
     // the argument
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
     // ')'
 }
Ejemplo n.º 18
0
 /**
  * @override
  */
 public function parse(\Doctrine\ORM\Query\Parser $parser)
 {
     $lexer = $parser->getLexer();
     $parser->match($lexer->lookahead['value']);
     $parser->match('(');
     $this->_stringPrimary = $parser->_StringPrimary();
     $parser->match(',');
     $this->_firstSimpleArithmeticExpression = $parser->_SimpleArithmeticExpression();
     $parser->match(',');
     $this->_secondSimpleArithmeticExpression = $parser->_SimpleArithmeticExpression();
     $parser->match(')');
 }
 /**
  * Feeds given parser with previously set literals
  * 
  * @param Parser $parser
  */
 protected function feedParserWithLiterals(Parser $parser)
 {
     $literalsMappingCount = count($this->literalsMapping);
     $lastLitteral = $literalsMappingCount - 1;
     for ($i = 0; $i < $literalsMappingCount; $i++) {
         $parserMethod = $this->literalsMapping[$i];
         $this->literals[$i] = $parser->{$parserMethod}();
         if ($i < $lastLitteral) {
             $parser->match(Lexer::T_COMMA);
         }
     }
 }
Ejemplo n.º 20
0
 /**
  * @override
  */
 public function parse(\Doctrine\ORM\Query\Parser $parser)
 {
     $lexer = $parser->getLexer();
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->stringPrimary = $parser->StringPrimary();
     $parser->match(Lexer::T_COMMA);
     $this->firstSimpleArithmeticExpression = $parser->SimpleArithmeticExpression();
     $parser->match(Lexer::T_COMMA);
     $this->secondSimpleArithmeticExpression = $parser->SimpleArithmeticExpression();
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
 /**
  * {@inheritdoc}
  */
 public function parse(Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->pathExpression = $parser->SingleValuedAssociationPathExpression();
     if ($parser->getLexer()->isNextToken(Lexer::T_COMMA)) {
         $parser->match(Lexer::T_COMMA);
         $parser->match(Lexer::T_STRING);
         $this->fieldMapping = $parser->getLexer()->token['value'];
     }
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
 public function parse(\Doctrine\ORM\Query\Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->fieldName = $parser->StringPrimary();
     $parser->match(Lexer::T_COMMA);
     $this->queryString = $parser->StringPrimary();
     if ($parser->getLexer()->lookahead['type'] == Lexer::T_COMMA) {
         $parser->match(Lexer::T_COMMA);
         $this->regconfig = $parser->StringPrimary();
     }
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Ejemplo n.º 23
0
 /**
  * {@inheritdoc}
  */
 public function parse(Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->parameters[self::SEPARATOR_KEY] = $parser->StringPrimary();
     $parser->match(Lexer::T_COMMA);
     $this->parameters[self::STRINGS_KEY][] = $parser->StringPrimary();
     while ($parser->getLexer()->isNextToken(Lexer::T_COMMA)) {
         $parser->match(Lexer::T_COMMA);
         $this->parameters[self::STRINGS_KEY][] = $parser->StringPrimary();
     }
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
 /**
  * {@inheritDoc}
  */
 public function feedParserWithLiterals(Parser $parser)
 {
     $lexer = $parser->getLexer();
     $this->literals[] = $parser->{$this->commonLiteralMapping}();
     $aheadType = $lexer->lookahead['type'];
     while (Lexer::T_CLOSE_PARENTHESIS !== $aheadType) {
         if (Lexer::T_COMMA === $aheadType) {
             $parser->match(Lexer::T_COMMA);
             $this->literals[] = $parser->{$this->commonLiteralMapping}();
         }
         $aheadType = $lexer->lookahead['type'];
     }
 }
Ejemplo n.º 25
0
 public function parse(\Doctrine\ORM\Query\Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $parser->match(Lexer::T_IDENTIFIER);
     $lexer = $parser->getLexer();
     $this->unit = $lexer->token['value'];
     $parser->match(Lexer::T_COMMA);
     $this->firstDatetimeExpression = $parser->ArithmeticPrimary();
     $parser->match(Lexer::T_COMMA);
     $this->secondDatetimeExpression = $parser->ArithmeticPrimary();
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Ejemplo n.º 26
0
 /**
  * {@inheritdoc}
  */
 public function parse(\Doctrine\ORM\Query\Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->parameters['separator'] = $parser->StringPrimary();
     $parser->match(Lexer::T_COMMA);
     $this->parameters['strings'][] = $parser->StringPrimary();
     while ($parser->getLexer()->isNextToken(Lexer::T_COMMA)) {
         $parser->match(Lexer::T_COMMA);
         $this->parameters['strings'][] = $parser->StringPrimary();
     }
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Ejemplo n.º 27
0
 public function parse(Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->expressions[] = $parser->ArithmeticFactor();
     $parser->match(Lexer::T_COMMA);
     $this->expressions[] = $parser->ArithmeticFactor();
     $lexer = $parser->getLexer();
     if ($lexer->lookahead['type'] === Lexer::T_COMMA) {
         $parser->match(Lexer::T_COMMA);
         $this->expressions[] = $parser->ArithmeticFactor();
     }
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Ejemplo n.º 28
0
 /**
  * @override
  */
 public function parse(\Doctrine\ORM\Query\Parser $parser)
 {
     $lexer = $parser->getLexer();
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     if (strcasecmp('leading', $lexer->lookahead['value']) === 0) {
         $parser->match(Lexer::T_LEADING);
         $this->leading = true;
     } else {
         if (strcasecmp('trailing', $lexer->lookahead['value']) === 0) {
             $parser->match(Lexer::T_TRAILING);
             $this->trailing = true;
         } else {
             if (strcasecmp('both', $lexer->lookahead['value']) === 0) {
                 $parser->match(Lexer::T_BOTH);
                 $this->both = true;
             }
         }
     }
     if ($lexer->isNextToken(Lexer::T_STRING)) {
         $parser->match(Lexer::T_STRING);
         $this->trimChar = $lexer->token['value'];
     }
     if ($this->leading || $this->trailing || $this->both || $this->trimChar) {
         $parser->match(Lexer::T_FROM);
     }
     $this->stringPrimary = $parser->StringPrimary();
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
 /**
  * Calculates total count of query records
  *
  * @param Query $query
  * @param \Doctrine\Common\Collections\ArrayCollection|array|null $parameters Query parameters.
  * @return integer
  */
 public function getCount(Query $query, $parameters = null)
 {
     if (!empty($parameters)) {
         $query = clone $query;
         $query->setParameters($parameters);
     }
     $parser = new Parser($query);
     $parserResult = $parser->parse();
     $parameterMappings = $parserResult->getParameterMappings();
     list($sqlParameters, $parameterTypes) = $this->processParameterMappings($query, $parameterMappings);
     $statement = $query->getEntityManager()->getConnection()->executeQuery('SELECT COUNT(*) FROM (' . $query->getSQL() . ') AS e', $sqlParameters, $parameterTypes);
     $result = $statement->fetchColumn();
     return $result ? (int) $result : 0;
 }
Ejemplo n.º 30
0
 /**
  * Parse the DQL
  *
  * @param \Doctrine\ORM\Query\Parser $parser
  */
 public function parse(Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->firstDateExpression = $parser->ArithmeticPrimary();
     $parser->match(Lexer::T_COMMA);
     $parser->match(Lexer::T_IDENTIFIER);
     $this->intervalExpression = $parser->ArithmeticPrimary();
     $parser->match(Lexer::T_IDENTIFIER);
     /* @var $lexer Lexer */
     $lexer = $parser->getLexer();
     $this->unit = $lexer->token['value'];
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }