Skip to content
docsv0.1.1

StorageArchiver

Packs a fixed list of filesystem paths (files and/or directories) into a single tar.gz archive via {@see PharData} — no shell-out, no `tar` binary dependency. Paths that no longer exist by the time {@see self::archive()} runs are skipped silently (storage directories come and go; a missing one isn't a backup failure). Archive mechanism decision (PharData vs ZipArchive): the well-known caveat is that `PharData::compress()`/write operations require `phar.readonly=0`, since that ini setting is `PHP_INI_PERDIR` and can't be flipped at runtime via `ini_set()`. This package targets that caveat by testing directly against the ini value rather than trusting it blindly: `phar.readonly` gates the *native* `.phar` executable-archive format, not the tar/zip container format `PharData` writes here. Verified empirically on this host (PHP 8.3.32): `ini_get('phar.readonly')` reports `"1"` (On) yet `PharData::addFile()`/`compress(Phar::GZ)` still write successfully. We therefore use `PharData` unconditionally and do NOT gate on `phar.readonly` (a static ini check would have produced a false negative here). Any failure to write (e.g. `ext-phar` missing or genuinely blocked) surfaces as a {@see RuntimeException} from {@see self::archive()} rather than being silently swallowed — if that happens in some other environment, the fix is `phar.readonly = Off` in php.ini, or a future `ZipArchive` fallback.

StorageArchiver::__construct()

public function __construct(array $paths):

Parameters

Parameters of __construct()
NameTypeDescription
$pathslist<string>

StorageArchiver::archive()

public function archive(string $destinationTarGz): void

Build `$destinationTarGz` from the constructor's paths that still exist. Directories are added recursively, preserving their relative file layout. An all-missing path list still produces a valid, readable (empty) archive.

Parameters

Parameters of archive()
NameTypeDescription
$destinationTarGzstring