Luminova Framework

PHP Luminova: Create ZIP Archives

Last updated: 2026-11-28 20:57:12

Package a file or directory into a ZIP archive, exclude entries with patterns, and track file counts.

Use Archive when you need to package local files for export or backup. ZIP creation requires PHP’s Zip extension. Use a writable destination outside the directory being archived, and choose a new output name to preserve an existing archive.


Usage

Run this from a bootstrapped Luminova application. Set $reportPath to an existing local file and $zipPath to a writable destination such as /tmp/report.zip.

use Luminova\Storage\Archive;

$added = 0;
$skipped = 0;

if (Archive::zip($zipPath, $reportPath, added: $added, skipped: $skipped)) {
    echo "Files counted as added: {$added}";
}

Class Definition

  • Full namespace: Luminova\Storage\Archive
  • This class is a concrete class.

Methods

zip

Create or overwrite a ZIP archive. For a directory, traverse its entries and apply the ignore patterns to candidate paths and basenames. The current implementation can store entry names with a leading slash. Inspect the stored names and file contents before distributing a ZIP.

public static function zip(
    string $destination,
    string $source,
    array $ignores = [],
    int &$added = 0,
    int &$skipped = 0,
): bool

Parameters:

ParameterTypeDescription
$destinationstringDestination ZIP path.
$sourcestringExisting local file or directory.
$ignoresstring[]Glob patterns for excluded paths or basenames (default: []).
$addedintOutput counter for files counted as added (default: 0).
$skippedintOutput counter for skipped entries (default: 0).

Return:

bool - true when at least one file was counted as added. The counter does not confirm that each write or archive close succeeded.

Throws:


tarGz

Build a TAR archive using Phar and request Gzip compression. The current implementation then renames the original TAR over the compressed output. A successful result can therefore leave an uncompressed TAR with a .tar.gz suffix. Use zip() when you need a compressed archive from this class.

public static function tarGz(string $destination, string $source): bool

Parameters:

ParameterTypeDescription
$destinationstringOutput path or basename. A trailing .tar or .tar.gz is normalized to .tar.gz.
$sourcestringExisting local file or directory.

Return:

bool - Rename result, or false when the source or intermediate TAR is missing.

Throws: