ParagonIE\EasyDB\EasyDB::escapeValueSet PHP Метод

escapeValueSet() публичный Метод

Input: ([1, 2, 3, 5], int) Output: "(1,2,3,5)"
public escapeValueSet ( array $values, string $type = 'string' ) : string
$values array
$type string
Результат string
    public function escapeValueSet(array $values, string $type = 'string') : string
    {
        if (empty($values)) {
            // Default value: a sub-query that will return an empty set
            return '(SELECT 1 WHERE FALSE)';
        }
        // No arrays of arrays, please
        if (!$this->is1DArray($values)) {
            throw new \InvalidArgumentException('Only one-dimensional arrays are allowed.');
        }
        // Build our array
        $join = [];
        foreach ($values as $k => $v) {
            switch ($type) {
                case 'int':
                    if (!\is_int($v)) {
                        throw new \InvalidArgumentException('Expected a integer at index ' . $k . ' of argument 1 passed to ' . static::class . '::' . __METHOD__ . '(), received ' . (\is_scalar($v) || \is_array($v) ? \gettype($v) : (\is_object($v) ? 'an instance of ' . \get_class($v) : \var_export($v, true))));
                    }
                    $join[] = (int) $v + 0;
                    break;
                case 'float':
                case 'decimal':
                case 'number':
                case 'numeric':
                    if (!\is_numeric($v)) {
                        throw new \InvalidArgumentException('Expected a number at index ' . $k . ' of argument 1 passed to ' . static::class . '::' . __METHOD__ . '(), received ' . (\is_scalar($v) || \is_array($v) ? \gettype($v) : (\is_object($v) ? 'an instance of ' . \get_class($v) : \var_export($v, true))));
                    }
                    $join[] = (double) $v + 0.0;
                    break;
                case 'string':
                    if (\is_numeric($v)) {
                        $v = (string) $v;
                    }
                    if (!\is_string($v)) {
                        throw new \InvalidArgumentException('Expected a string at index ' . $k . ' of argument 1 passed to ' . static::class . '::' . __METHOD__ . '(), received ' . (\is_scalar($v) || \is_array($v) ? \gettype($v) : (\is_object($v) ? 'an instance of ' . \get_class($v) : \var_export($v, true))));
                    }
                    $join[] = $this->pdo->quote($v, \PDO::PARAM_STR);
                    break;
                default:
                    break 2;
            }
        }
        if (empty($join)) {
            return '(SELECT 1 WHERE FALSE)';
        }
        return '(' . \implode(', ', $join) . ')';
    }