_file = $directory->openFile($directory->getRelativePath($file), 'r'); } catch (\Magento\Framework\Exception\FileSystemException $e) { throw new \LogicException("Unable to open file: '{$file}'"); } if ($delimiter) { $this->_delimiter = $delimiter; } $this->_enclosure = $enclosure; parent::__construct($this->_getNextRow()); } /** * Close file handle * * @return void */ public function destruct() { if (is_object($this->_file)) { $this->_file->close(); } } /** * Read next line from CSV-file * * @return array|bool */ protected function _getNextRow() { $parsed = $this->_file->readCsv(0, $this->_delimiter, $this->_enclosure); if (is_array($parsed) && count($parsed) != $this->_colQty) { foreach ($parsed as $element) { if (strpos($element, "'") !== false) { $this->_foundWrongQuoteFlag = true; break; } } } else { $this->_foundWrongQuoteFlag = false; } return is_array($parsed) ? $parsed : []; } /** * Rewind the \Iterator to the first element (\Iterator interface) * * @return void */ public function rewind() { $this->_file->seek(0); $this->_getNextRow(); // skip first line with the header parent::rewind(); } }