Zip
in package
V360Tech\Zip - ZipArchive toolbox
This class provide methods to handle single zip archive
Tags
Table of Contents
- $mask : int
- Mask for the extraction folder (if it should be created)
- $password : string|null
- zip file password (only for extract)
- $path : string|null
- Current base path
- $skip_mode : string
- Select files to skip
- $supported_skip_modes : array<string|int, mixed>
- Supported skip modes
- $zip_archive : ZipArchive
- ZipArchive internal pointer
- $zip_file : string|null
- zip file name
- $zip_status_codes : array<string|int, mixed>
- Array of well known zip status codes
- __construct() : mixed
- Class constructor
- add() : Zip
- Add files to zip archive
- addFromString() : void
- Create file form content and add to zip archive
- check() : bool
- Check a zip archive
- close() : bool
- Close the zip archive
- create() : Zip
- Create a new zip archive
- delete() : Zip
- Delete files from zip archive
- extract() : bool
- Extract files from zip archive
- getArchive() : ZipArchive
- Get current ZipArchive object
- getFileObject() : SplFileObject
- Get an SplFileObject for the zip file
- getMask() : int
- Get current extraction folder mask
- getPassword() : string
- Get current extraction password
- getPath() : string
- Get current base path
- getSkipped() : string
- Get current skip mode (HIDDEN, ZANYSOFT, ALL, NONE)
- getZipFile() : string
- Get current zip file
- has() : bool
- Check if zip archive has a file
- listFiles() : array<string|int, mixed>
- Get a list of files in archive (array)
- open() : Zip
- Open a zip archive
- setArchive() : Zip
- Set the current ZipArchive object
- setMask() : Zip
- Set extraction folder mask
- setPassword() : Zip
- Set extraction password
- setPath() : Zip
- Set current base path (just to add relative files to zip archive)
- setSkipped() : Zip
- Set files to skip
- addItem() : void
- Add item to zip archive
- deleteItem() : mixed
- Delete item from zip archive
- getArchiveFiles() : array<string|int, mixed>
- Get a list of file contained in zip archive before extraction
- getStatus() : string
- Get status from zip status code
- openZipFile() : ZipArchive
- Open a zip file
Properties
$mask
Mask for the extraction folder (if it should be created)
private
int
$mask
= 0777
$password
zip file password (only for extract)
private
string|null
$password
= null
$path
Current base path
private
string|null
$path
= null
$skip_mode
Select files to skip
private
string
$skip_mode
= 'NONE'
$supported_skip_modes
Supported skip modes
private
array<string|int, mixed>
$supported_skip_modes
= ['HIDDEN', 'ZANYSOFT', 'ALL', 'NONE']
$zip_archive
ZipArchive internal pointer
private
ZipArchive
$zip_archive
= null
$zip_file
zip file name
private
string|null
$zip_file
= null
$zip_status_codes
Array of well known zip status codes
private
static array<string|int, mixed>
$zip_status_codes
= [\ZipArchive::ER_OK => 'No error', \ZipArchive::ER_MULTIDISK => 'Multi-disk zip archives not supported', \ZipArchive::ER_RENAME => 'Renaming temporary file failed', \ZipArchive::ER_CLOSE => 'Closing zip archive failed', \ZipArchive::ER_SEEK => 'Seek error', \ZipArchive::ER_READ => 'Read error', \ZipArchive::ER_WRITE => 'Write error', \ZipArchive::ER_CRC => 'CRC error', \ZipArchive::ER_ZIPCLOSED => 'Containing zip archive was closed', \ZipArchive::ER_NOENT => 'No such file', \ZipArchive::ER_EXISTS => 'File already exists', \ZipArchive::ER_OPEN => 'Can\'t open file', \ZipArchive::ER_TMPOPEN => 'Failure to create temporary file', \ZipArchive::ER_ZLIB => 'Zlib error', \ZipArchive::ER_MEMORY => 'Malloc failure', \ZipArchive::ER_CHANGED => 'Entry has been changed', \ZipArchive::ER_COMPNOTSUPP => 'Compression method not supported', \ZipArchive::ER_EOF => 'Premature EOF', \ZipArchive::ER_INVAL => 'Invalid argument', \ZipArchive::ER_NOZIP => 'Not a zip archive', \ZipArchive::ER_INTERNAL => 'Internal error', \ZipArchive::ER_INCONS => 'Zip archive inconsistent', \ZipArchive::ER_REMOVE => 'Can\'t remove file', \ZipArchive::ER_DELETED => 'Entry has been deleted']
Methods
__construct()
Class constructor
public
__construct([string $zip_file = null ]) : mixed
Parameters
- $zip_file : string = null
-
ZIP file name
Return values
mixed —add()
Add files to zip archive
public
add(mixed $file_path[, bool $flatroot = false ]) : Zip
Parameters
- $file_path : mixed
-
file path to add or an array of files path
- $flatroot : bool = false
-
in case of directory, specify if root folder should be flatten or not
Return values
Zip —addFromString()
Create file form content and add to zip archive
public
addFromString(string $name, string $string) : void
Parameters
- $name : string
-
File name with extension
- $string : string
-
File content
Return values
void —check()
Check a zip archive
public
check(string $zip_file) : bool
Parameters
- $zip_file : string
-
ZIP file name
Return values
bool —close()
Close the zip archive
public
close() : bool
Return values
bool —create()
Create a new zip archive
public
create(string $zip_file[, bool $overwrite = false ]) : Zip
Parameters
- $zip_file : string
-
ZIP file name
- $overwrite : bool = false
-
overwrite existing file (if any)
Return values
Zip —delete()
Delete files from zip archive
public
delete(mixed $filename) : Zip
Parameters
- $filename : mixed
-
filename to delete or an array of filenames
Return values
Zip —extract()
Extract files from zip archive
public
extract(string $destination[, mixed $files = null ]) : bool
Parameters
- $destination : string
-
Destination path
- $files : mixed = null
-
(optional) a filename or an array of filenames
Return values
bool —getArchive()
Get current ZipArchive object
public
final getArchive() : ZipArchive
Return values
ZipArchive —getFileObject()
Get an SplFileObject for the zip file
public
getFileObject() : SplFileObject
Return values
SplFileObject —getMask()
Get current extraction folder mask
public
final getMask() : int
Return values
int —getPassword()
Get current extraction password
public
final getPassword() : string
Return values
string —getPath()
Get current base path
public
final getPath() : string
Return values
string —getSkipped()
Get current skip mode (HIDDEN, ZANYSOFT, ALL, NONE)
public
final getSkipped() : string
Return values
string —getZipFile()
Get current zip file
public
final getZipFile() : string
Return values
string —has()
Check if zip archive has a file
public
has(string $file, int $flags) : bool
Parameters
- $file : string
-
File
- $flags : int
-
(optional) ZipArchive::FL_NOCASE, ZipArchive::FL_NODIR seperated by bitwise OR
Return values
bool —listFiles()
Get a list of files in archive (array)
public
listFiles() : array<string|int, mixed>
Return values
array<string|int, mixed> —open()
Open a zip archive
public
open(string $zip_file) : Zip
Parameters
- $zip_file : string
-
ZIP file name
Return values
Zip —setArchive()
Set the current ZipArchive object
public
final setArchive(ZipArchive $zip) : Zip
Parameters
- $zip : ZipArchive
Return values
Zip —setMask()
Set extraction folder mask
public
final setMask(int $mask) : Zip
Parameters
- $mask : int
Return values
Zip —setPassword()
Set extraction password
public
final setPassword(string $password) : Zip
Parameters
- $password : string
Return values
Zip —setPath()
Set current base path (just to add relative files to zip archive)
public
setPath(string $path) : Zip
Parameters
- $path : string
Return values
Zip —setSkipped()
Set files to skip
public
final setSkipped(string $mode) : Zip
Parameters
- $mode : string
-
[HIDDEN, ZANYSOFT, ALL, NONE]
Return values
Zip —addItem()
Add item to zip archive
private
addItem(string $file[, bool $flatroot = false ][, string|null $base = null ]) : void
Parameters
- $file : string
-
File to add (realpath)
- $flatroot : bool = false
-
(optional) If true, source directory will be not included
- $base : string|null = null
-
(optional) Base to record in zip file
Tags
Return values
void —deleteItem()
Delete item from zip archive
private
deleteItem(string $file) : mixed
Parameters
- $file : string
-
File to delete (zippath)
Return values
mixed —getArchiveFiles()
Get a list of file contained in zip archive before extraction
private
getArchiveFiles() : array<string|int, mixed>
Return values
array<string|int, mixed> —getStatus()
Get status from zip status code
private
static getStatus(int $code) : string
Parameters
- $code : int
-
ZIP status code
Return values
string —openZipFile()
Open a zip file
private
static openZipFile(string $zip_file[, int $flags = null ]) : ZipArchive
Parameters
- $zip_file : string
-
ZIP status code
- $flags : int = null
-
ZIP status code