/** * Creates SELECT statement. * @param Connection $connection * @param string|array|Traversable $columns * @param string|Result $source Table name or subquery * @throws InvalidArgumentException */ public function __construct(Connection $connection, $columns = null, $source = null) { parent::__construct($connection); // Input check if ($columns === null && $source === null) { throw new InvalidArgumentException('Missing select source.'); } if ($source === null) { $source = $columns; $columns = '*'; } if (!is_string($source) && !$source instanceof self) { throw new InvalidArgumentException('Source must be a string or Neevo\\Result.'); } $columns = is_string($columns) ? explode(',', $columns) : ($columns instanceof Traversable ? iterator_to_array($columns) : (array) $columns); if (empty($columns)) { throw new InvalidArgumentException('No columns given.'); } if ($source instanceof self) { $this->subqueries[] = $source; } $this->type = Manager::STMT_SELECT; $this->columns = array_map('trim', $columns); $this->source = $source; $this->detectTypes = (bool) $connection['result']['detectTypes']; $this->setRowClass($connection['rowClass']); }