Skip to content

Commit

Permalink
Expose SplFileObject flags to be configurable during CSVFile creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ppetrov committed May 9, 2018
1 parent 9c16cc3 commit a101dc0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/CsvFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CsvFile extends File implements \Countable {
private $start_column = 0;
private $columns_to_skip = array();

function __construct($file, $delimiter = ',', $enclosure = '"', $escape = "\\") {
function __construct($file, $delimiter = ',', $enclosure = '"', $escape = "\\", $flags = null) {
if (!file_exists($file)) {
throw new Exception("File $file does not exist. ");
}
Expand All @@ -29,8 +29,12 @@ function __construct($file, $delimiter = ',', $enclosure = '"', $escape = "\\")
throw new Exception("Empty file. ");
}

if ( is_null( $flags ) ) {
$flags = File::READ_CSV | File::READ_AHEAD | File::SKIP_EMPTY | File::DROP_NEW_LINE;
}

parent::__construct($file, 'r+');
$this->setFlags(File::READ_CSV | File::READ_AHEAD | File::SKIP_EMPTY | File::DROP_NEW_LINE);
$this->setFlags($flags);
$this->setCsvControl($delimiter, $enclosure, $escape);
}

Expand Down

0 comments on commit a101dc0

Please sign in to comment.