public function buildLikeCondition($operator, $operands, &$params)
{
if (!isset($operands[0], $operands[1])) {
throw new InvalidParamException("Operator '{$operator}' requires two operands.");
}
$escape = isset($operands[2]) ? $operands[2] : ['%' => '\\%', '_' => '\\_', '\\' => '\\\\'];
unset($operands[2]);
if (!preg_match('/^(AND |OR |)(((NOT |))I?LIKE)/', $operator, $matches)) {
throw new InvalidParamException("Invalid operator '{$operator}'.");
}
$andor = ' ' . (!empty($matches[1]) ? $matches[1] : 'AND ');
$not = !empty($matches[3]);
$operator = $matches[2];
list($column, $values) = $operands;
if (!is_array($values)) {
$values = [$values];
}
if (empty($values)) {
return $not ? '' : '0=1';
}
if (strpos($column, '(') === false) {
$column = $this->db->quoteColumnName($column);
}
$parts = [];
foreach ($values as $value) {
if ($value instanceof Expression) {
foreach ($value->params as $n => $v) {
$params[$n] = $v;
}
$phName = $value->expression;
} else {
$phName = self::PARAM_PREFIX . count($params);
$params[$phName] = empty($escape) ? $value : '%' . strtr($value, $escape) . '%';
}
$parts[] = "{$column} {$operator} {$phName}";
}
return implode($andor, $parts);
}