/**
* 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);
}