PHP Class Chumper\Zipper\Zipper

Class Zipper
Datei anzeigen Open project: chumper/zipper Class Usage Examples

Public Methods

Method Description
__construct ( Illuminate\Filesystem\Filesystem $fs = null ) Constructor
__destruct ( ) Destructor
add ( $pathToAdd, $fileName = null ) Add one or multiple files to the zip.
addEmptyDir ( $dirName ) : void Add an empty directory
addString ( $filename, $content ) Add a file to the zip using its contents
close ( ) Closes the zip file and frees all handles
contains ( $fileInArchive ) : boolean Checks if a file is present in the archive
delete ( ) Deletes the archive file
extractTo ( $path, array $files = [], integer $method = Zipper::BLACKLIST ) Extracts the opened zip archive to the specified location
you can provide an array of files and folders and define if they should be a white list or a black list to extract.
folder ( $path ) Sets the internal folder to the given path.
Useful for extracting only a segment of a zip file.
getArchiveType ( ) : string Get the type of the Archive
getCurrentFolderPath ( ) : string Get the current internal folder pointer
getFileContent ( $filePath ) : mixed Gets the content of a single file if available
getFileHandler ( ) : Illuminate\Filesystem\Filesystem
getFilePath ( ) : string Returns the path of the current zip file if there is one.
getInternalPath ( ) : string Gets the path to the internal folder
getRepository ( ) : Chumper\Zipper\Repositories\RepositoryInterface
getStatus ( ) : integer Gets the status of the zip.
home ( ) Resets the internal folder to the root of the zip file.
listFiles ( ) : array List files that are within the archive
make ( $pathToFile, Chumper\Zipper\Repositories\RepositoryInterface | string $type = 'zip' ) Create a new zip Archive if the file does not exists opens a zip archive if the file exists
phar ( $pathToFile ) Create a new phar file or open one
rar ( $pathToFile ) Create a new rar file or open one
remove ( $fileToRemove ) Remove a file or array of files and folders from the zip archive
usePassword ( $password ) : boolean Sets the password to be used for decompressing
zip ( $pathToFile ) Create a new zip archive or open an existing one

Private Methods

Method Description
addDir ( $pathToDir )
addFile ( $pathToAdd, $fileName = null ) Add the file to the zip
addFromString ( $filename, $content ) Add the file to the zip from content
createArchiveFile ( $pathToZip ) : boolean
extractWithBlackList ( $path, $filesArray )
extractWithWhiteList ( $path, $filesArray )

Method Details

__construct() public method

Constructor
public __construct ( Illuminate\Filesystem\Filesystem $fs = null )
$fs Illuminate\Filesystem\Filesystem

__destruct() public method

Destructor
public __destruct ( )

add() public method

Add one or multiple files to the zip.
public add ( $pathToAdd, $fileName = null )
$pathToAdd array|string An array or string of files and folders to add

addEmptyDir() public method

Add an empty directory
public addEmptyDir ( $dirName ) : void
$dirName
return void

addString() public method

Add a file to the zip using its contents
public addString ( $filename, $content )
$filename string The name of the file to create
$content string The file contents

close() public method

Closes the zip file and frees all handles
public close ( )

contains() public method

Checks if a file is present in the archive
public contains ( $fileInArchive ) : boolean
$fileInArchive
return boolean

delete() public method

Deletes the archive file
public delete ( )

extractTo() public method

Extracts the opened zip archive to the specified location
you can provide an array of files and folders and define if they should be a white list or a black list to extract.
public extractTo ( $path, array $files = [], integer $method = Zipper::BLACKLIST )
$path string The path to extract to
$files array An array of files
$method integer The Method the files should be treated

folder() public method

Sets the internal folder to the given path.
Useful for extracting only a segment of a zip file.
public folder ( $path )
$path

getArchiveType() public method

Get the type of the Archive
public getArchiveType ( ) : string
return string

getCurrentFolderPath() public method

Get the current internal folder pointer
public getCurrentFolderPath ( ) : string
return string

getFileContent() public method

Gets the content of a single file if available
public getFileContent ( $filePath ) : mixed
$filePath string The full path (including all folders) of the file in the zip
return mixed returns the content or throws an exception

getFileHandler() public method

public getFileHandler ( ) : Illuminate\Filesystem\Filesystem
return Illuminate\Filesystem\Filesystem

getFilePath() public method

Returns the path of the current zip file if there is one.
public getFilePath ( ) : string
return string The path to the file

getInternalPath() public method

Gets the path to the internal folder
public getInternalPath ( ) : string
return string

getRepository() public method

public getRepository ( ) : Chumper\Zipper\Repositories\RepositoryInterface
return Chumper\Zipper\Repositories\RepositoryInterface

getStatus() public method

Gets the status of the zip.
public getStatus ( ) : integer
return integer The status of the internal zip file

home() public method

Resets the internal folder to the root of the zip file.
public home ( )

listFiles() public method

List files that are within the archive
public listFiles ( ) : array
return array

make() public method

Create a new zip Archive if the file does not exists opens a zip archive if the file exists
public make ( $pathToFile, Chumper\Zipper\Repositories\RepositoryInterface | string $type = 'zip' )
$pathToFile string The file to open
$type Chumper\Zipper\Repositories\RepositoryInterface | string The type of the archive, defaults to zip, possible are zip, phar

phar() public method

Create a new phar file or open one
public phar ( $pathToFile )
$pathToFile

rar() public method

Create a new rar file or open one
public rar ( $pathToFile )
$pathToFile

remove() public method

Remove a file or array of files and folders from the zip archive
public remove ( $fileToRemove )
$fileToRemove array|string The path/array to the files in the zip

usePassword() public method

Sets the password to be used for decompressing
public usePassword ( $password ) : boolean
$password
return boolean

zip() public method

Create a new zip archive or open an existing one
public zip ( $pathToFile )
$pathToFile