예제 #1
0
 /**
  * Read expand or select clause.
  * 
  * @param string  $value    expand or select clause to read.
  * @param boolean $isSelect true means $value is value of select clause
  *                          else value of expand clause.
  * 
  * @return array(array) An array of 'PathSegment's, each of which is array
  *                      of 'SubPathSegment's
  */
 private function _readExpandOrSelect($value, $isSelect)
 {
     $pathSegments = array();
     $lexer = new ExpressionLexer($value);
     $i = 0;
     while ($lexer->getCurrentToken()->Id != ExpressionTokenId::END) {
         $lastSegment = false;
         if ($isSelect && $lexer->getCurrentToken()->Id == ExpressionTokenId::STAR) {
             $lastSegment = true;
             $subPathSegment = $lexer->getCurrentToken()->Text;
             $lexer->nextToken();
         } else {
             $subPathSegment = $lexer->readDottedIdentifier();
         }
         if (!array_key_exists($i, $pathSegments)) {
             $pathSegments[$i] = array();
         }
         $pathSegments[$i][] = $subPathSegment;
         $tokenId = $lexer->getCurrentToken()->Id;
         if ($tokenId != ExpressionTokenId::END) {
             if ($lastSegment || $tokenId != ExpressionTokenId::SLASH) {
                 $lexer->validateToken(ExpressionTokenId::COMMA);
                 $i++;
             }
             $lexer->nextToken();
         }
     }
     return $pathSegments;
 }
예제 #2
0
 public function testValidateToken()
 {
     $expression = "IntIdentifier eq 123";
     $lexer = new ExpressionLexer($expression);
     $lexer->validateToken(ExpressionTokenId::IDENTIFIER);
     $lexer->nextToken();
     $token = $lexer->getCurrentToken();
     try {
         $lexer->validateToken(ExpressionTokenId::INTEGER_LITERAL);
         $this->fail('An expected ODataException has not been raised');
     } catch (ODataException $ex) {
         $this->assertStringStartsWith('Syntax Error at position 16', $ex->getMessage());
     }
 }
예제 #3
0
 /**
  * Read orderby clause.
  * 
  * @param string $value orderby clause to read.
  * 
  * @return array(array) An array of 'OrderByPathSegment's, each of which 
  *                      is array of 'OrderBySubPathSegment's
  * 
  * @throws ODataException If any syntax error found while reading the clause
  */
 private function _readOrderBy($value)
 {
     $orderByPathSegments = array();
     $lexer = new ExpressionLexer($value);
     $i = 0;
     while ($lexer->getCurrentToken()->Id != ExpressionTokenId::END) {
         $orderBySubPathSegment = $lexer->readDottedIdentifier();
         if (!array_key_exists($i, $orderByPathSegments)) {
             $orderByPathSegments[$i] = array();
         }
         $orderByPathSegments[$i][] = $orderBySubPathSegment;
         $tokenId = $lexer->getCurrentToken()->Id;
         if ($tokenId != ExpressionTokenId::END) {
             if ($tokenId != ExpressionTokenId::SLASH) {
                 if ($tokenId != ExpressionTokenId::COMMA) {
                     $lexer->validateToken(ExpressionTokenId::IDENTIFIER);
                     $identifier = $lexer->getCurrentToken()->Text;
                     if ($identifier !== 'asc' && $identifier !== 'desc') {
                         // force lexer to throw syntax error as we found
                         // unexpected identifier
                         $lexer->validateToken(ExpressionTokenId::DOT);
                     }
                     $orderByPathSegments[$i][] = '*' . $identifier;
                     $lexer->nextToken();
                     $tokenId = $lexer->getCurrentToken()->Id;
                     if ($tokenId != ExpressionTokenId::END) {
                         $lexer->validateToken(ExpressionTokenId::COMMA);
                         $i++;
                     }
                 } else {
                     $i++;
                 }
             }
             $lexer->nextToken();
         }
     }
     return $orderByPathSegments;
 }