/** * Transforms the \Webmozart\Expression\Expression to a Doctrine \Doctrine\ORM\Query\Expr. * * @param Key $expr * * @return Comparison|\Doctrine\ORM\Query\Expr\Func */ protected function toExpr(Key $expr) { $left = $expr->getKey(); if (strpos($left, '.') !== false) { $this->shouldJoin($left); } else { $left = $this->getRootAlias() . '.' . $left; } $comparator = $expr->getExpression(); $right = $comparator->getComparedValue(); if ($comparator instanceof NotEquals) { return $this->qb->expr()->neq($left, $right); } elseif ($comparator instanceof In) { if (is_array($right)) { return $this->qb->expr()->in($left, $right); } else { return $this->qb->expr()->like($left, '%' . $right . '%'); } } return $this->qb->expr()->eq($left, $right); }
private function traverseKey(Key $expr) { $innerExpr1 = $expr->getExpression(); $innerExpr2 = $this->traverse($innerExpr1); if ($innerExpr1 === $innerExpr2) { return $expr; } return $innerExpr2 ? new Key($expr->getKey(), $innerExpr2) : null; }