protected function addWhere($condition, array $params, $type = null)
{
$args = [];
if (null === $type) {
$type = CompositeExpression::TYPE_AND;
}
if (is_string($condition)) {
$condition = [$condition];
}
if (is_array($condition)) {
foreach ($condition as $key => $value) {
if (!is_numeric($key)) {
$name = $this->parameter($key);
$params[$name] = $value;
$value = "{$key} = :{$name}";
}
$args[] = $value;
}
} elseif ($condition instanceof Closure) {
$query = $this->newQuery();
$query->from($this->getPart('from'));
call_user_func($condition, $query);
$args[] = $query->getPart('where');
$params = $query->params();
}
$this->params($params);
$where = $this->getPart('where');
if ($where instanceof CompositeExpression && $where->getType() === $type) {
$where->addMultiple($args);
} else {
array_unshift($args, $where);
$where = new CompositeExpression($type, $args);
}
return $this->addPart('where', $where);
}