class CSVFIReader in Feed Import 7.3
CSV Reader class, used to read csv files.
Hierarchy
- class \FeedImportConfigurable
- class \FeedImportReader
- class \FeedImportUniVectorReader
- class \CSVFIReader
- class \FeedImportUniVectorReader
- class \FeedImportReader
Expanded class hierarchy of CSVFIReader
1 string reference to 'CSVFIReader'
- feed_import_feed_import_reader_info in ./
feed_import.module - Implements hook_feed_import_reader_info().
File
- feed_import_base/
inc/ feed_import_readers.inc, line 531 - This file contains implementations of feed import readers.
View source
class CSVFIReader extends FeedImportUniVectorReader {
// File handle.
protected $fh;
// Column names.
protected $columns = FALSE;
/**
* {@inheritdoc}
*/
public function init() {
// Require url.
if (empty($this->options['url'])) {
return FALSE;
}
// Set default options.
$this->options += array(
'length' => 0,
'delimiter' => ',',
'enclosure' => '"',
'escape' => '\\',
'use_column_names' => FALSE,
'stream' => NULL,
);
// Check for stream options.
if ($ctx = $this
->getStreamContext($this->options['stream'])) {
// Open the file using stream options.
$this->fh = fopen($this->options['url'], 'rb', FALSE, $ctx);
}
else {
// Open the file.
$this->fh = fopen($this->options['url'], 'rb');
}
if (!$this->fh) {
return FALSE;
}
// Check to see if column names are used.
if ($this->options['use_column_names']) {
if ($this->columns = $this
->get()) {
$this->columns = array_flip($this->columns);
}
else {
return FALSE;
}
}
return TRUE;
}
/**
* {@inheritdoc}
*/
public function get() {
return fgetcsv($this->fh, $this->options['length'], $this->options['delimiter'], $this->options['enclosure'], $this->options['escape']);
}
/**
* {@inheritdoc}
*/
public function formatPath($path) {
$path = parent::formatPath($path);
if ($this->columns) {
foreach ($path as &$p) {
if (isset($this->columns[$p])) {
$p = $this->columns[$p];
}
}
}
return $path;
}
/**
* {@inheritdoc}
*/
public function __destruct() {
// Close file handle if any.
if ($this->fh) {
try {
fclose($this->fh);
} catch (Exception $e) {
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CSVFIReader:: |
protected | property | ||
CSVFIReader:: |
protected | property | ||
CSVFIReader:: |
public | function |
Override this to preprocess your paths before they are used in map(). Overrides FeedImportUniVectorReader:: |
|
CSVFIReader:: |
public | function |
This method returns the next available item or NULL if there are no items
left. Overrides FeedImportReader:: |
|
CSVFIReader:: |
public | function |
Here you'll init your reader. Overrides FeedImportReader:: |
|
CSVFIReader:: |
public | function |
Destructor. Overrides FeedImportReader:: |
|
FeedImportConfigurable:: |
protected | property | ||
FeedImportConfigurable:: |
public static | function | Helper function to get lines of a string | |
FeedImportConfigurable:: |
public | function | Sets options for this instance | 4 |
FeedImportReader:: |
protected | property | ||
FeedImportReader:: |
public | function | Returns a stream context | |
FeedImportReader:: |
final public | function | Constructor of reader. Constructor is final but you'll have to implement init() to init your reader. | |
FeedImportUniVectorReader:: |
public | function |
Returns a value mapped from obj by path. Overrides FeedImportReader:: |