protected function CSV::setupFile in Migrate Source CSV 8.2
Setup the file.
Return value
\SplFileObject Returns the file object.
1 call to CSV::setupFile()
- CSV::initializeIterator in src/
Plugin/ migrate/ source/ CSV.php - Initializes the iterator with the source data.
File
- src/
Plugin/ migrate/ source/ CSV.php, line 103
Class
- CSV
- Source for CSV.
Namespace
Drupal\migrate_source_csv\Plugin\migrate\sourceCode
protected function setupFile() {
// Set basics of CSV behavior based on configuration.
$delimiter = $this
->getConfiguration()['delimiter'];
$enclosure = $this
->getConfiguration()['enclosure'];
$escape = $this
->getConfiguration()['escape'];
$this->file
->setCsvControl($delimiter, $enclosure, $escape);
$this->file
->setFlags($this
->getConfiguration()['file_flags']);
// Figure out what CSV column(s) to use. Use either the header row(s) or
// explicitly provided column name(s).
if ($this
->getConfiguration()['header_row_count']) {
$this->file
->setHeaderRowCount($this
->getConfiguration()['header_row_count']);
// Find the last header line.
$this->file
->rewind();
$this->file
->seek($this->file
->getHeaderRowCount() - 1);
$row = $this->file
->current();
foreach ($row as $header) {
$header = trim($header);
$column_names[] = [
$header => $header,
];
}
$this->file
->setColumnNames($column_names);
}
// An explicit list of column name(s) will override any header row(s).
if ($this
->getConfiguration()['column_names']) {
$this->file
->setColumnNames($this
->getConfiguration()['column_names']);
}
return $this->file;
}