> For the complete documentation index, see [llms.txt](https://quantumphp.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quantumphp.gitbook.io/docs/packages/archive/contracts.md).

# 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 `phar` and `zip`
* throws when the adapter name is unknown
* returns the same cached `Archive` instance for repeated calls with the same adapter type

## Setup contract

Before any archive operation, call:

```php
$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): void`
* `offsetExists(string $filename): bool`
* `addEmptyDir(string $directory): bool`
* `addFile(string $filePath, ?string $entryName = null): bool`
* `addFromString(string $entryName, string $content): bool`
* `addMultipleFiles(array $fileNames): bool`
* `count(): int`
* `extractTo(string $pathToExtract, $files = null): bool`
* `deleteFile(string $filename): bool`
* `deleteMultipleFiles(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 `$files` argument in `extractTo()`
* ZIP ignores the optional `$files` argument in `extractTo()`
* PHAR exposes `removeArchive()` but ZIP does not


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://quantumphp.gitbook.io/docs/packages/archive/contracts.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
