Exemplo n.º 1
0
 /**
  * Validate operands of an relational operation
  * 
  * @param ExpressionToken    $expressionToken The expression token
  * @param AbstractExpression $leftArgument    The left argument expression
  * @param AbstractExpression $rightArgument   The right argument expression
  * 
  * @return void
  */
 public static function verifyRelationalOpArguments($expressionToken, $leftArgument, $rightArgument)
 {
     //for null operands only equality operators are allowed
     $null = new Null1();
     if ($leftArgument->typeIs($null) || $rightArgument->typeIs($null)) {
         if (strcmp($expressionToken->Text, ODataConstants::KEYWORD_EQUAL) != 0 && strcmp($expressionToken->Text, ODataConstants::KEYWORD_NOT_EQUAL) != 0) {
             throw ODataException::createSyntaxError(Messages::expressionParserOperatorNotSupportNull($expressionToken->Text, $expressionToken->Position));
         }
         return;
     }
     //for guid operands only equality operators are allowed
     $guid = new Guid();
     if ($leftArgument->typeIs($guid) && $rightArgument->typeIs($guid)) {
         if (strcmp($expressionToken->Text, ODataConstants::KEYWORD_EQUAL) != 0 && strcmp($expressionToken->Text, ODataConstants::KEYWORD_NOT_EQUAL) != 0) {
             throw ODataException::createSyntaxError(Messages::expressionParserOperatorNotSupportGuid($expressionToken->Text, $expressionToken->Position));
         }
         return;
     }
     //for binary operands only equality operators are allowed
     $binary = new Binary();
     if ($leftArgument->typeIs($binary) && $rightArgument->typeIs($binary)) {
         if (strcmp($expressionToken->Text, ODataConstants::KEYWORD_EQUAL) != 0 && strcmp($expressionToken->Text, ODataConstants::KEYWORD_NOT_EQUAL) != 0) {
             throw ODataException::createSyntaxError(Messages::expressionParserOperatorNotSupportBinary($expressionToken->Text, $expressionToken->Position));
         }
         return;
     }
     //TODO: eq and ne is valid for 'resource reference'
     //navigation also verify here
     $functions = array_merge(self::relationalOperationFunctions(), self::stringComparisonFunctions());
     $function = self::findFunctionWithPromotion($functions, array($leftArgument, $rightArgument), false);
     if ($function == null) {
         self::incompatibleError($expressionToken, array($leftArgument, $rightArgument));
     }
 }
Exemplo n.º 2
0
 /**
  *  Populate map table 
  *
  * @param AbstractExpression $nullCheckExpTree The expression to verfiy.
  * 
  * @return void
  * 
  * @throws ODataException
  */
 private function _map($nullCheckExpTree)
 {
     if ($nullCheckExpTree instanceof LogicalExpression) {
         $this->_map($nullCheckExpTree->getLeft());
         $this->_map($nullCheckExpTree->getRight());
     } else {
         if ($nullCheckExpTree instanceof UnaryExpression) {
             $this->_map($nullCheckExpTree->getChild());
         } else {
             if ($nullCheckExpTree instanceof FunctionCallExpression) {
                 $param = $nullCheckExpTree->getParamExpressions();
                 $this->_map($param[0]);
             } else {
                 if ($nullCheckExpTree instanceof PropertyAccessExpression) {
                     $parent = $nullCheckExpTree;
                     $key = null;
                     do {
                         $key = $parent->getResourceProperty()->getName() . '_' . $key;
                         $parent = $parent->getParent();
                     } while ($parent != null);
                     $this->_mapTable[$key] = $nullCheckExpTree;
                 } else {
                     throw ODataException::createSyntaxError(Messages::expressionParser2UnexpectedExpression(get_class($nullCheckExpTree)));
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Recursive function to process each node of the expression
  * 
  * @param AbstractExpression $expression Current node to process.
  * 
  * @return string The language specific expression.
  */
 private function _processExpressionNode(AbstractExpression $expression)
 {
     if ($expression instanceof ArithmeticExpression) {
         $left = $this->_processExpressionNode($expression->getLeft());
         $right = $this->_processExpressionNode($expression->getRight());
         return $this->_expressionProvider->onArithmeticExpression($expression->getNodeType(), $left, $right);
     }
     if ($expression instanceof LogicalExpression) {
         $left = $this->_processExpressionNode($expression->getLeft());
         $right = $this->_processExpressionNode($expression->getRight());
         return $this->_expressionProvider->onLogicalExpression($expression->getNodeType(), $left, $right);
     }
     if ($expression instanceof RelationalExpression) {
         $left = $this->_processExpressionNode($expression->getLeft());
         $right = $this->_processExpressionNode($expression->getRight());
         return $this->_expressionProvider->onRelationalExpression($expression->getNodeType(), $left, $right);
     }
     if ($expression instanceof ConstantExpression) {
         return $this->_expressionProvider->onConstantExpression($expression->getType(), $expression->getValue());
     }
     if ($expression instanceof PropertyAccessExpression) {
         return $this->_expressionProvider->onPropertyAccessExpression($expression);
     }
     if ($expression instanceof FunctionCallExpression) {
         $params = array();
         foreach ($expression->getParamExpressions() as $paramExpression) {
             $params[] = $this->_processExpressionNode($paramExpression);
         }
         return $this->_expressionProvider->onFunctionCallExpression($expression->getFunctionDescription(), $params);
     }
     if ($expression instanceof UnaryExpression) {
         $child = $this->_processExpressionNode($expression->getChild());
         return $this->_expressionProvider->onUnaryExpression($expression->getNodeType(), $child);
     }
 }