Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 39 and 311]

(no description)

File Size: 217 lines (8 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: ZipHelper  - X-Ref

Class ZipHelper
This class provides helper functions to create zip files

__construct($entityFactory)   X-Ref

param: InternalEntityFactory $entityFactory Factory to create entities

createZip($tmpFolderPath)   X-Ref
Returns a new ZipArchive instance pointing at the given path.

param: string $tmpFolderPath Path of the temp folder where the zip file will be created
return: \ZipArchive

getZipFilePath(\ZipArchive $zip)   X-Ref

param: \ZipArchive $zip An opened zip archive object
return: string Path where the zip file of the given folder will be created

addFileToArchive($zip, $rootFolderPath, $localFilePath, $existingFileMode = self::EXISTING_FILES_OVERWRITE)   X-Ref
Adds the given file, located under the given root folder to the archive.
The file will be compressed.

Example of use:
addFileToArchive($zip, '/tmp/xlsx/foo', 'bar/baz.xml');
=> will add the file located at '/tmp/xlsx/foo/bar/baz.xml' in the archive, but only as 'bar/baz.xml'

param: \ZipArchive $zip An opened zip archive object
param: string $rootFolderPath Path of the root folder that will be ignored in the archive tree.
param: string $localFilePath Path of the file to be added, under the root folder
param: string $existingFileMode Controls what to do when trying to add an existing file
return: void

addUncompressedFileToArchive($zip, $rootFolderPath, $localFilePath, $existingFileMode = self::EXISTING_FILES_OVERWRITE)   X-Ref
Adds the given file, located under the given root folder to the archive.
The file will NOT be compressed.

Example of use:
addUncompressedFileToArchive($zip, '/tmp/xlsx/foo', 'bar/baz.xml');
=> will add the file located at '/tmp/xlsx/foo/bar/baz.xml' in the archive, but only as 'bar/baz.xml'

param: \ZipArchive $zip An opened zip archive object
param: string $rootFolderPath Path of the root folder that will be ignored in the archive tree.
param: string $localFilePath Path of the file to be added, under the root folder
param: string $existingFileMode Controls what to do when trying to add an existing file
return: void

addFileToArchiveWithCompressionMethod($zip, $rootFolderPath, $localFilePath, $existingFileMode, $compressionMethod)   X-Ref
Adds the given file, located under the given root folder to the archive.
The file will NOT be compressed.

Example of use:
addUncompressedFileToArchive($zip, '/tmp/xlsx/foo', 'bar/baz.xml');
=> will add the file located at '/tmp/xlsx/foo/bar/baz.xml' in the archive, but only as 'bar/baz.xml'

param: \ZipArchive $zip An opened zip archive object
param: string $rootFolderPath Path of the root folder that will be ignored in the archive tree.
param: string $localFilePath Path of the file to be added, under the root folder
param: string $existingFileMode Controls what to do when trying to add an existing file
param: int $compressionMethod The compression method
return: void

canChooseCompressionMethod()   X-Ref

return: bool Whether it is possible to choose the desired compression method to be used

addFolderToArchive($zip, $folderPath, $existingFileMode = self::EXISTING_FILES_OVERWRITE)   X-Ref

param: \ZipArchive $zip An opened zip archive object
param: string $folderPath Path to the folder to be zipped
param: string $existingFileMode Controls what to do when trying to add an existing file
return: void

shouldSkipFile($zip, $itemLocalPath, $existingFileMode)   X-Ref

param: \ZipArchive $zip
param: string $itemLocalPath
param: string $existingFileMode
return: bool Whether the file should be added to the archive or skipped

getNormalizedRealPath($path)   X-Ref
Returns canonicalized absolute pathname, containing only forward slashes.

param: string $path Path to normalize
return: string Normalized and canonicalized path

closeArchiveAndCopyToStream($zip, $streamPointer)   X-Ref
Closes the archive and copies it into the given stream

param: \ZipArchive $zip An opened zip archive object
param: resource $streamPointer Pointer to the stream to copy the zip
return: void

copyZipToStream($zipFilePath, $pointer)   X-Ref
Streams the contents of the zip file into the given stream

param: string $zipFilePath Path of the zip file
param: resource $pointer Pointer to the stream to copy the zip
return: void