class Zip (View source)

Wrapper for ZIP functions.

Properties

protected Filesystem $filesystem The Filesystem instance to use.
protected FunctionInspector $functionInspector The FunctionInspector instance to use.
protected bool $enableNativeCommands Can we try to use native commands?
protected array $availableNativeCommands Cache for the available native commands.

Methods

__construct(Filesystem $filesystem, FunctionInspector $functionInspector)

Initialize the instance.

setFilesystem(Filesystem $filesystem)

Set the Filesystem instance to use.

Filesystem
getFilesystem()

Get the Filesystem instance to use.

enableNativeCommands()

State that we can try to use native commands.

disableNativeCommands()

State that we can NOT try to use native commands.

bool
nativeCommandsEnabled()

Can we try to use native commands?

bool
isNativeCommandAvailable(string $command)

Check if a native command is available.

bool
mayUseNativeCommand(string $command)

Check if a native command is available and if we may use it.

unzip(string $zipFile, string $destinationDirectory, array $options = [])

Decompress a ZIP archive to a directory.

zip(string $sourceDirectory, string $zipFile, array $options = [])

Compress the contents of a directory to a ZIP archive.

array
listContents(string $zipFile, array $options = [])

List the contents of a ZIP archive.

string
describeZipArchiveError(ZipArchive $zip, int $errorCode)

Describe a ZipArchive related problem.

unzipNative(string $zipFile, string $destinationDirectory, array $options)

Decompress a ZIP archive to a directory using the native 'unzip' command.

unzipPHP(string $zipFile, string $destinationDirectory, array $options)

Decompress a ZIP archive to a directory using the PHP functions.

zipNative(string $sourceDirectory, string $zipFile, array $options)

Compress the contents of a directory to a ZIP archive using the native 'zip' command.

zipPHP(string $sourceDirectory, string $zipFile, array $options)

Compress the contents of a directory to a ZIP archive using the PHP functions.

Details

__construct(Filesystem $filesystem, FunctionInspector $functionInspector)

Initialize the instance.

Parameters

Filesystem $filesystem
FunctionInspector $functionInspector

setFilesystem(Filesystem $filesystem)

Set the Filesystem instance to use.

Parameters

Filesystem $filesystem

Filesystem getFilesystem()

Get the Filesystem instance to use.

Return Value

Filesystem

enableNativeCommands()

State that we can try to use native commands.

disableNativeCommands()

State that we can NOT try to use native commands.

bool nativeCommandsEnabled()

Can we try to use native commands?

Return Value

bool

bool isNativeCommandAvailable(string $command)

Check if a native command is available.

Parameters

string $command

Return Value

bool

protected bool mayUseNativeCommand(string $command)

Check if a native command is available and if we may use it.

Parameters

string $command

Return Value

bool

unzip(string $zipFile, string $destinationDirectory, array $options = [])

Decompress a ZIP archive to a directory.

Parameters

string $zipFile the source ZIP archive
string $destinationDirectory the destination folder
array $options { @var bool $skipCheck Skip test compressed archive data }

Exceptions

Exception

zip(string $sourceDirectory, string $zipFile, array $options = [])

Compress the contents of a directory to a ZIP archive.

Parameters

string $sourceDirectory the directory to compress
string $zipFile the ZIP file to create (it will be deleted if already existing, unless the 'append' option is set to true)
array $options { @var bool $includeDotFiles Shall the zip file include files and folders whose name starts with a dot? @var bool $skipCheck Skip test compressed archive data @var int $level Compression level (0 to 9) @var bool $append Append to an existing archive instead of overwriting it? }

Exceptions

Exception

array listContents(string $zipFile, array $options = [])

List the contents of a ZIP archive.

Parameters

string $zipFile the ZIP file to inspect
array $options { @var bool $skipCheck Skip test compressed archive data @var bool $excludeDirs Don't include directories @var bool $excludeFiles Don't include files }

Return Value

array The keys of the resulting array contain the paths to the items, and the values will be arrays, whose keys are: - string 'type' For directories it will be 'D', for files it will be 'F' - \DateTime 'date' Last modification date/time - int 'originalSize' (only for files) Uncompressed size of the file - int 'compressedSize' (only for files) Compressed size of the file

Exceptions

Exception

protected string describeZipArchiveError(ZipArchive $zip, int $errorCode)

Describe a ZipArchive related problem.

Parameters

ZipArchive $zip
int $errorCode

Return Value

string

protected unzipNative(string $zipFile, string $destinationDirectory, array $options)

Decompress a ZIP archive to a directory using the native 'unzip' command.

Parameters

string $zipFile
string $destinationDirectory
array $options

Exceptions

Exception

protected unzipPHP(string $zipFile, string $destinationDirectory, array $options)

Decompress a ZIP archive to a directory using the PHP functions.

Parameters

string $zipFile
string $destinationDirectory
array $options

Exceptions

Exception

protected zipNative(string $sourceDirectory, string $zipFile, array $options)

Compress the contents of a directory to a ZIP archive using the native 'zip' command.

Parameters

string $sourceDirectory
string $zipFile
array $options

Exceptions

Exception

protected zipPHP(string $sourceDirectory, string $zipFile, array $options)

Compress the contents of a directory to a ZIP archive using the PHP functions.

Parameters

string $sourceDirectory
string $zipFile
array $options

Exceptions

Exception