class Zip implements ZipInterface, Countable (View source)

comodojo/zip - ZipArchive toolbox

Traits

Skip mode helper trait.
File mask helper trait.
Password helper trait.
Path helper trait.
Archive helper trait.
Set/get the archive comment.

Methods

setSkipMode(string $mode)

Set files to skip

string
getSkipMode()

Get current skip mode

setMask(int $mask)

Set the mask of the extraction folder

int
getMask()

Get current mask of the extraction folder

ZipArchive|null
getArchive()

No description

setPassword(string $password)

Set zip password

string|null
getPassword()

Get current zip password

setPath(string|null $path = null)

Set current base path (to add relative files to zip archive)

string|null
getPath()

Get current base path

setArchive(ZipArchive $zip)

Set the current ZipArchive object

setComment(string $comment)

Set the comment for the current archive

string|null
getComment()

Get the current zip archive comment

__construct(string $zip_file)

Class constructor

static ZipInterface
open(string $zip_file)

Open a zip archive (static constructor)

static bool
check(string $zip_file)

Check a zip archive (static constructor)

static ZipInterface
create(string $zip_file, bool $overwrite = false)

Create a new zip archive (static constructor)

int
count()

Count the number of files in the archive

string
getZipFile()

Get current zip file

array
listFiles()

Get the list of files in the archive as an array

bool
extract(string $destination, mixed $files = null)

Extract files from zip archive

add(mixed $file_name_or_array, bool $flatten_root_folder = false, int $compression = self::CM_DEFAULT, int $encryption = self::EM_NONE)

Add files to the ZipArchive

delete(mixed $file_name_or_array)

Delete files from ZipArchive

bool
close()

Close the ZipArchive

Details

ZipInterface setSkipMode(string $mode)

Set files to skip

Supported skip modes: Zip::SKIP_NONE - skip no files Zip::SKIP_HIDDEN - skip hidden files Zip::SKIP_ALL - skip HIDDEN + COMODOJO ghost files Zip::SKIP_COMODOJO - skip comodojo ghost files

Parameters

string $mode Skip file mode

Return Value

ZipInterface

Exceptions

ZipException

string getSkipMode()

Get current skip mode

Return Value

string

ZipInterface setMask(int $mask)

Set the mask of the extraction folder

Parameters

int $mask Integer representation of the file mask

Return Value

ZipInterface

int getMask()

Get current mask of the extraction folder

Return Value

int

abstract ZipArchive|null getArchive()

Return Value

ZipArchive|null

ZipInterface setPassword(string $password)

Set zip password

Parameters

string $password

Return Value

ZipInterface

protected string|null getPassword()

Get current zip password

Return Value

string|null

ZipInterface setPath(string|null $path = null)

Set current base path (to add relative files to zip archive)

Parameters

string|null $path

Return Value

ZipInterface

Exceptions

ZipException

string|null getPath()

Get current base path

Return Value

string|null

ZipInterface setArchive(ZipArchive $zip)

Set the current ZipArchive object

Parameters

ZipArchive $zip

Return Value

ZipInterface

ZipInterface setComment(string $comment)

Set the comment for the current archive

Parameters

string $comment

Return Value

ZipInterface

string|null getComment()

Get the current zip archive comment

Return Value

string|null

__construct(string $zip_file)

Class constructor

Parameters

string $zip_file ZIP file name

Exceptions

ZipException

static ZipInterface open(string $zip_file)

Open a zip archive (static constructor)

Parameters

string $zip_file File name

Return Value

ZipInterface

Exceptions

ZipException

static bool check(string $zip_file)

Check a zip archive (static constructor)

Parameters

string $zip_file ZIP file name

Return Value

bool

Exceptions

ZipException

static ZipInterface create(string $zip_file, bool $overwrite = false)

Create a new zip archive (static constructor)

Parameters

string $zip_file ZIP file name
bool $overwrite Overwrite existing file (if any)

Return Value

ZipInterface

Exceptions

ZipException

int count()

Count the number of files in the archive

Return Value

int

string getZipFile()

Get current zip file

Return Value

string

array listFiles()

Get the list of files in the archive as an array

Return Value

array

Exceptions

ZipException

bool extract(string $destination, mixed $files = null)

Extract files from zip archive

Parameters

string $destination Destination path
mixed $files (optional) a filename or an array of filenames

Return Value

bool

Exceptions

ZipException

ZipInterface add(mixed $file_name_or_array, bool $flatten_root_folder = false, int $compression = self::CM_DEFAULT, int $encryption = self::EM_NONE)

Add files to the ZipArchive

Parameters

mixed $file_name_or_array Filename to add or an array of filenames
bool $flatten_root_folder In case of directory, specify if root folder should be flatten or not
int $compression Compression algorithm to use (default CM_DEFAULT)
int $encryption

Return Value

ZipInterface

Exceptions

ZipException

ZipInterface delete(mixed $file_name_or_array)

Delete files from ZipArchive

Parameters

mixed $file_name_or_array Filename to delete or an array of filenames

Return Value

ZipInterface

Exceptions

ZipException

bool close()

Close the ZipArchive

Return Value

bool

Exceptions

ZipException