public function escapeValueSet(array $values, string $type = 'string') : string
{
if (empty($values)) {
// Default value: a subquery that will return an empty set
return '(SELECT 1 WHERE FALSE)';
}
// No arrays of arrays, please
if (!\is1DArray($values)) {
throw new \TypeError(\trk('errors.database.array_passed'));
}
// Build our array
$join = [];
foreach ($values as $v) {
switch ($type) {
case 'int':
if (!\is_int($v)) {
throw new \TypeError(\__('%s is not an integer', 'default', $v));
}
$join[] = (int) $v + 0;
break;
case 'float':
case 'decimal':
case 'number':
case 'numeric':
if (!\is_numeric($v)) {
throw new \TypeError(\__('%s is not a number', 'default', $v));
}
$join[] = (double) $v + 0.0;
break;
case 'string':
if (\is_numeric($v)) {
$v = (string) $v;
}
if (!\is_string($v)) {
throw new \TypeError(\__('%s is not a string.', 'default', \serialize($v)));
}
$join[] = $this->pdo->quote($v, \PDO::PARAM_STR);
break;
default:
break 2;
}
}
if (empty($join)) {
return '(SELECT 1 WHERE FALSE)';
}
return '(' . \implode(', ', $join) . ')';
}