/** * @param string $type * @param string $filePath * @param array $options * * @throws UnsupportedTypeException * @throws FileNotFoundException */ public function __construct($type, $filePath, array $options = []) { $this->type = $type; $this->filePath = $filePath; $this->fileInfo = new \SplFileInfo($filePath); if (!$this->fileInfo->isFile()) { throw new FileNotFoundException(sprintf('File "%s" could not be found', $this->filePath)); } $mimeType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $this->filePath); if ('application/zip' === $mimeType && Type::XLSX !== $this->fileInfo->getExtension()) { $this->extractZipArchive(); } $this->reader = ReaderFactory::create($type); if (isset($options['reader_options'])) { $this->setReaderOptions($options['reader_options']); } $this->reader->open($this->filePath); $this->reader->getSheetIterator()->rewind(); $sheet = $this->reader->getSheetIterator()->current(); $sheet->getRowIterator()->rewind(); $this->headers = $sheet->getRowIterator()->current(); $this->rows = $sheet->getRowIterator(); }