Archive Contracts
This page summarizes the behavior you can rely on when integrating Archive.
Factory contract
ArchiveFactory::get(string $type = ArchiveType::PHAR): Archive
- defaults to
phar - supports
pharandzip - throws when the adapter name is unknown
- returns the same cached
Archiveinstance for repeated calls with the same adapter type
Setup contract
Before any archive operation, call:
$archive->setName('/absolute/path/to/archive.zip');
If the name was not set, adapter operations throw an archive exception.
Shared archive methods
The wrapper forwards these methods to both built-in adapters:
setName(string $archiveName): voidoffsetExists(string $filename): booladdEmptyDir(string $directory): booladdFile(string $filePath, ?string $entryName = null): booladdFromString(string $entryName, string $content): booladdMultipleFiles(array $fileNames): boolcount(): intextractTo(string $pathToExtract, $files = null): booldeleteFile(string $filename): booldeleteMultipleFiles(array $fileNames): bool
If you call another method through the wrapper and the active adapter does not implement it, the wrapper throws.
File input contract
addFile() validates that the source file exists before adding it.
Missing source files raise an archive exception instead of returning false.
addMultipleFiles() expects an associative array of archive entry name => source file path.
Return-value contract
The package mixes exceptions and boolean failures.
Expect exceptions for:
- missing archive name
- unsupported adapter type
- missing source file for
addFile() - calling a method that the current adapter does not support
- archive open failures
Expect false for many adapter-level operational failures such as add, extract, and delete problems after the archive is already open.
Adapter-specific contract gaps
These differences matter in real integrations:
- PHAR honors the optional
$filesargument inextractTo() - ZIP ignores the optional
$filesargument inextractTo() - PHAR exposes
removeArchive()but ZIP does not