Skip to content

Commit

Permalink
Merge pull request #32 from ho-nl/JeroenVanLeusden-patch-1
Browse files Browse the repository at this point in the history
Allow setting custom escape character for FileCsv reader
  • Loading branch information
Jeroen authored Apr 26, 2022
2 parents fc838f1 + ecefc7d commit 1d21300
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/Streamer/FileCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,44 @@
*/
class FileCsv
{
/**
* @var string
*/
/** @var string $requestFile */
private $requestFile;

/**
* @var ConsoleOutput
*/
/** @var ConsoleOutput $consoleOutput */
private $consoleOutput;

/**
* @var DirectoryList
*/
/** @var DirectoryList $directoryList */
private $directoryList;

/**
* @var Log
*/
/** @var Log $log */
private $log;

/**
* @var string
*/
/** @var string $delimiter */
private $delimiter;

/**
* @var array
*/
/** @var array $headers */
private $headers;

/** @var string $escapeCharacter */
private $escapeCharacter;

/**
* @param ConsoleOutput $consoleOutput
* @param DirectoryList $directoryList
* @param string $requestFile Relative or absolute path to filename.
* @param Log $log
* @param string $delimiter
* @param array $headers
* @param string $escapeCharacter
*/
public function __construct(
ConsoleOutput $consoleOutput,
DirectoryList $directoryList,
string $requestFile,
Log $log,
string $delimiter,
array $headers = []
array $headers = [],
string $escapeCharacter = ''
) {
$this->consoleOutput = $consoleOutput;
$this->directoryList = $directoryList;
Expand Down Expand Up @@ -96,7 +90,7 @@ public function getIterator()
$requestFile = fopen($requestFile, 'r');

$csvReader = \League\Csv\Reader::createFromStream($requestFile);
$csvReader->setEscape('');
$csvReader->setEscape($this->escapeCharacter);
if (empty($this->headers)) {
$csvReader->setHeaderOffset(0);
}
Expand Down

0 comments on commit 1d21300

Please sign in to comment.