Zip

 class Winter\Storm\Filesystem\Zip
extends ZipArchive

Properties

protected $folderPrefix : string

Folder prefix

Methods

public final __construct ()

Lock down the constructor for this class.

Returns
mixed

public add (string $source, array $options = []) : self

Adds a source file or directory to a Zip file.

Parameters
Property Description
$source
string

Path to the source file or directory.

$options
array

Optional. An array of options. Supports the following options:

  • recursive, which determines whether to add subdirectories and files recursively. Defaults to true.
  • includeHidden, which determines whether to add hidden files and directories. Defaults to false.
  • baseDir, which determines the base directory to use when adding files.
  • baseglob, which defines a glob pattern to match files and directories to add.
Returns
self

public static extract (string $source, string $destination, array $options = []) : bool

Extracts an existing ZIP file.

Parameters
Property Description
$source
string

Path to the ZIP file.

$destination
string

Path to the destination directory.

$options
array

Optional. An array of options. Only one option is currently supported: mask, which defines the permission mask to use when creating the destination folder.

Returns
bool

public folder (string $name, $source = null) : self

Creates a new folder inside the Zip file, and optionally adds the given source files/folders to this folder.

Source can be a single path, an array of paths or a callback which allows you to manipulate the Zip file.

Parameters
Property Description
$name
string
$source
mixed
Returns
self

public static make (string $destination, string | callable | array | null $source = null, array $options = []) : static

Creates a new empty Zip file, optionally populating it with given source files.

Source can be a single path, an array of paths or a callback which allows you to manipulate the Zip file.

Parameters
Property Description
$destination
string

Path to the destination ZIP file.

$source
string | callable | array | null

Optional. Path to the source file(s) or a callback.

$options
array

Optional. An array of options. Uses the same options as Zip::add().

Returns
static

public remove (array | string $source) : self

Removes file(s) or folder(s) from the Zip file.

Does not support wildcards.

Parameters
Property Description
$source
array | string
Returns
self

protected removePathPrefix (string $prefix, string $path) : string

Removes a prefix from a given path.

Parameters
Property Description
$prefix
string
$path
string
Returns
string
Copyright © 2024 Winter CMS