Пример #1
0
 public function visitComparisonExpression(Expr\ComparisonExpression $expr)
 {
     $field = $expr->getField();
     $value = $this->visitValueIdentifier($expr->getValue());
     switch ($expr->getOperator()) {
         case Expr\ComparisonExpression::EQ:
             if (null === $value) {
                 return $field . Literals::L_COLON . Literals::L_NULL;
             }
             return $field . Literals::L_COLON . Literals::L_EQ . Literals::L_COLON . $value;
         case Expr\ComparisonExpression::NEQ:
             if (null === $value) {
                 return $field . Literals::L_COLON . Literals::L_ANY;
             }
             return $field . Literals::L_COLON . Literals::L_NE . Literals::L_COLON . $value;
         case Expr\ComparisonExpression::GT:
             return $field . Literals::L_COLON . Literals::L_GT . Literals::L_COLON . $value;
         case Expr\ComparisonExpression::GTE:
             return $field . Literals::L_COLON . Literals::L_GE . Literals::L_COLON . $value;
         case Expr\ComparisonExpression::LT:
             return $field . Literals::L_COLON . Literals::L_LT . Literals::L_COLON . $value;
         case Expr\ComparisonExpression::LTE:
             return $field . Literals::L_COLON . Literals::L_LE . Literals::L_COLON . $value;
         default:
             throw new \RuntimeException(sprintf('Unknown Operator[%s] for ComparisonExpression.', (string) $textComparison->getOperator()));
             break;
     }
 }
Пример #2
0
 public function visitComparisonExpression(Expr\ComparisonExpression $expr)
 {
     // fixme
     $rawValue = $this->visitValueIdentifier($expr->getValue());
     $parameterName = str_replace('.', '_', $expr->getField()) . '_' . substr(md5($rawValue), 0, 5);
     $parameter = new Parameter($parameterName, $rawValue);
     $placeHolder = ':' . $parameterName;
     $qb = $this->getQueryBuilder();
     switch ($expr->getOperator()) {
         case Expr\ComparisonExpression::EQ:
             if (null === $rawValue) {
                 return $qb->expr()->isNull($this->visitField($expr->getField()));
             }
             $qb->getParameters()->add($parameter);
             return $qb->expr()->eq($this->visitField($expr->getField()), $placeHolder);
         case Expr\ComparisonExpression::NEQ:
             if (null === $rawValue) {
                 return $qb->expr()->isNotNull($this->visitField($expr->getField()));
             }
             $qb->getParameters()->add($parameter);
             return $qb->expr()->neq($this->visitField($expr->getField()), $placeHolder);
         case Expr\ComparisonExpression::GT:
             $qb->getParameters()->add($parameter);
             return $qb->expr()->gt($this->visitField($expr->getField()), $placeHolder);
         case Expr\ComparisonExpression::GTE:
             $qb->getParameters()->add($parameter);
             return $qb->expr()->gte($this->visitField($expr->getField()), $placeHolder);
         case Expr\ComparisonExpression::LT:
             $qb->getParameters()->add($parameter);
             return $qb->expr()->lt($this->visitField($expr->getField()), $placeHolder);
         case Expr\ComparisonExpression::LTE:
             $qb->getParameters()->add($parameter);
             return $qb->expr()->lte($this->visitField($expr->getField()), $placeHolder);
             break;
         default:
             throw new \RuntimeException(sprintf('Unknown Operator[%s] for ComparisonExpression.', (string) $textComparison->getOperator()));
             break;
     }
 }