API / Minn\Ops / Unzip

Unzip final readonly class

Minn\Ops\Unzip · public/minn/src/Minn/Ops/Unzip.php · 112 lines

An archive unpacked as unzip_file() unpacks it (probe unzip-file): into the destination through the filesystem the site set up, every folder made first (the destination and its missing parents included), resource-fork entries (__MACOSX/) and entries whose names climb out or are absolute left out; refused when the disk cannot take twice the unpacked size and a little more. pre_unzip_file may answer first, and unzip_file is handed the result, each with the folders to make and the space needed. An archive the reader cannot open is refused in the words of the library the reference falls back to.

Constants and properties

privatereadonly object $filesystem

Promoted from the constructor.

privatereadonly Closure $filter

Promoted from the constructor.

privatereadonly int $dirMode

Promoted from the constructor.

privatereadonly int $fileMode

Promoted from the constructor.

Public

new__construct(object $filesystem, Closure $filter, int $dirMode, int $fileMode)#
$filesystemobjectthe site's WP_Filesystem (mkdir, is_dir, put_contents)
$filterClosure(string, mixed...): mixedapplies a filter, as apply_filters does
staticvalid(string $file): bool#

Whether a file is a zip archive that opens and passes its consistency check (wp_zip_file_is_valid).

methodinto(string $file, string $to): mixed#

The archive's files under the destination: true, a refusal, or what pre_unzip_file answered instead.

Internals 3

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privateread(ZipArchive $archive): array#

The entries to write, the folders they need (each archive folder and every parent of a file), and their unpacked size.

@return array{0: array<int, string>, 1: list<string>, 2: int} index => name, folders, bytes
privatesafe(string $name): bool#

Whether an entry's name stays inside the destination: no climbing segment, not absolute, no drive.

privatewrite(ZipArchive $archive, array $entries, string $to, array $needed): Minn\Runtime\Refusal|true#
$entriesarray<int, string>@param list<string> $needed