Example #1
0
 /**
  * Zips the root folder and streams the contents of the zip into the given stream
  *
  * @param resource $streamPointer Pointer to the stream to copy the zip
  * @return void
  */
 public function zipRootFolderAndCopyToStream($streamPointer)
 {
     $zipHelper = new ZipHelper($this->rootFolder);
     // In order to have the file's mime type detected properly, files need to be added
     // to the zip file in a particular order.
     // "[Content_Types].xml" then at least 2 files located in "xl" folder should be zipped first.
     $zipHelper->addFileToArchive($this->rootFolder, self::CONTENT_TYPES_XML_FILE_NAME);
     $zipHelper->addFileToArchive($this->rootFolder, self::XL_FOLDER_NAME . '/' . self::WORKBOOK_XML_FILE_NAME);
     $zipHelper->addFileToArchive($this->rootFolder, self::XL_FOLDER_NAME . '/' . self::STYLES_XML_FILE_NAME);
     $zipHelper->addFolderToArchive($this->rootFolder, ZipHelper::EXISTING_FILES_SKIP);
     $zipHelper->closeArchiveAndCopyToStream($streamPointer);
     // once the zip is copied, remove it
     $this->deleteFile($zipHelper->getZipFilePath());
 }
Example #2
0
 /**
  * @return void
  */
 public function testGeneratedFileShouldHaveTheCorrectMimeType()
 {
     // Only PHP7+ gives the correct mime type since it requires adding
     // uncompressed files to the final archive (which support was added in PHP7)
     if (!ZipHelper::canChooseCompressionMethod()) {
         $this->markTestSkipped('The PHP version used does not support setting the compression method of archived files,
             resulting in the mime type to be detected incorrectly.');
     }
     $fileName = 'test_mime_type.ods';
     $resourcePath = $this->getGeneratedResourcePath($fileName);
     $dataRow = ['foo'];
     $this->writeToODSFile([$dataRow], $fileName);
     $finfo = new \finfo(FILEINFO_MIME_TYPE);
     $this->assertEquals('application/vnd.oasis.opendocument.spreadsheet', $finfo->file($resourcePath));
 }
Example #3
0
 /**
  * Zips the root folder and streams the contents of the zip into the given stream
  *
  * @param resource $streamPointer Pointer to the stream to copy the zip
  * @return void
  */
 public function zipRootFolderAndCopyToStream($streamPointer)
 {
     $zipHelper = new ZipHelper($this->rootFolder);
     // In order to have the file's mime type detected properly, files need to be added
     // to the zip file in a particular order.
     // @see http://www.jejik.com/articles/2010/03/how_to_correctly_create_odf_documents_using_zip/
     $zipHelper->addUncompressedFileToArchive($this->rootFolder, self::MIMETYPE_FILE_NAME);
     $zipHelper->addFolderToArchive($this->rootFolder, ZipHelper::EXISTING_FILES_SKIP);
     $zipHelper->closeArchiveAndCopyToStream($streamPointer);
     // once the zip is copied, remove it
     $this->deleteFile($zipHelper->getZipFilePath());
 }
Example #4
0
 /**
  * Zips the root folder and streams the contents of the zip into the given stream
  *
  * @param resource $streamPointer Pointer to the stream to copy the zip
  * @return void
  */
 public function zipRootFolderAndCopyToStream($streamPointer)
 {
     $zipHelper = new ZipHelper();
     $zipHelper->zipFolderAndCopyToStream($this->rootFolder, $streamPointer);
     // once the zip is copied, remove it
     $this->deleteFile($zipHelper->getZipFilePath($this->rootFolder));
 }