/** * Open file and detect column names * * There must be column names in the first line * * @param string $file * @param \Magento\Framework\Filesystem\Directory\Write $directory * @param string $delimiter * @param string $enclosure * @throws \LogicException */ public function __construct($file, \Magento\Framework\Filesystem\Directory\Write $directory, $delimiter = ',', $enclosure = '"') { try { $this->_file = $directory->openFile($directory->getRelativePath($file), 'r'); } catch (\Magento\Framework\Filesystem\FilesystemException $e) { throw new \LogicException("Unable to open file: '{$file}'"); } $this->_delimiter = $delimiter; $this->_enclosure = $enclosure; parent::__construct($this->_getNextRow()); }
/** * Create new sitemap file * * @param null|string $fileName * @param string $type * @return void * @throws \Magento\Framework\Exception\LocalizedException */ protected function _createSitemap($fileName = null, $type = self::TYPE_URL) { if (!$fileName) { $this->_sitemapIncrement++; $fileName = $this->_getCurrentSitemapFilename($this->_sitemapIncrement); } $path = rtrim($this->getSitemapPath(), '/') . '/' . $fileName; $this->_stream = $this->_directory->openFile($path); $fileHeader = sprintf($this->_tags[$type][self::OPEN_TAG_KEY], $type); $this->_stream->write($fileHeader); $this->_fileSize = strlen($fileHeader . sprintf($this->_tags[$type][self::CLOSE_TAG_KEY], $type)); }