From ecefc7dbd6216bb626bfd612093292c4ef51ab25 Mon Sep 17 00:00:00 2001 From: Jeroen Date: Tue, 26 Apr 2022 10:28:43 +0200 Subject: [PATCH] Allow setting custom escape character for FileCsv reader --- src/Streamer/FileCsv.php | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/Streamer/FileCsv.php b/src/Streamer/FileCsv.php index 850959f..59996cb 100644 --- a/src/Streamer/FileCsv.php +++ b/src/Streamer/FileCsv.php @@ -22,42 +22,35 @@ */ 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, @@ -65,7 +58,8 @@ public function __construct( string $requestFile, Log $log, string $delimiter, - array $headers = [] + array $headers = [], + string $escapeCharacter = '' ) { $this->consoleOutput = $consoleOutput; $this->directoryList = $directoryList; @@ -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); }