Skip to content

Internals Installer Package Extractor

Stefan Crkvenjakov edited this page Oct 7, 2026 · 1 revision

installer\package\Extractor

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/installer/package/Extractor.php · Snapshot 8411f4287706.

Installation validates archives and manifests, moves files, persists metadata, copies data into storage, invokes an optional hook and emits an event. These operations do not form one atomic transaction.

Imports and dependencies

use installer\interfaces\package\IExtractor;
use RuntimeException;
use vfs\transient\interfaces\ITransientStorageEntry;
use ZipArchive;

Extractor

Declaration and architectural role

class Extractor implements IExtractor

Constants, enum cases, traits and properties

Declarations below preserve visibility, type, default and modifiers exactly. A typed property without an initializer remains uninitialized until its constructor or another method assigns it. Mutable fields belong to this instance unless marked static; readonly fields can be initialized once. Constructor-promoted properties are also listed below.

Member Declaration Purpose or source contract
Constructor-promoted private ZipArchive $zip Initialized from the constructor argument; default expression is evaluated when the argument is omitted.
Constructor-promoted private ITransientStorageEntry $target Initialized from the constructor argument; default expression is evaluated when the argument is omitted.
Constructor-promoted private string $destination Initialized from the constructor argument; default expression is evaluated when the argument is omitted.

Method index

Method Signature
__construct public function __construct( private ZipArchive $zip, private ITransientStorageEntry $target, private string $destination )
extract public function extract(): void
getZip public function getZip(): ZipArchive
getTarget public function getTarget(): ITransientStorageEntry
getDestination public function getDestination(): string
setTarget public function setTarget(ITransientStorageEntry $target): void
setDestination public function setDestination(string $destination): void
zipVerify public function zipVerify(): void
makeDestination private function makeDestination(): void

__construct

Source line 14

public function __construct(
        private ZipArchive $zip,
        private ITransientStorageEntry $target,
        private string $destination
    );

Parameters

Parameter Type, modifiers and default Purpose
$zip private ZipArchive $zip Operation input; the exact use, validation and propagation are shown in the implementation trace.
$target private ITransientStorageEntry $target Operation input; the exact use, validation and propagation are shown in the implementation trace.
$destination private string $destination Operation input; the exact use, validation and propagation are shown in the implementation trace.

Concrete no-op/default hook: this method performs no work. Override it where the lifecycle or extension contract calls for behavior.

extract

Source line 24

public function extract(): void

@throws \RuntimeException

Explicit exceptions: RuntimeException. The guards in the implementation below show when each is raised; exceptions from collaborators also propagate unless caught.

Implementation, validation guards and interaction order
/**
     * @inheritDoc
     * @throws \RuntimeException
     */
    public function extract(): void
    {
        $this->destination .= hash("md5", $this->target->getName());
        $this->makeDestination();

        $result = $this->zip->open($this->target->getPath());
        if ($result !== true) throw new RuntimeException("Could not open package archive (ZIP error {$result}).");
        try {
            $this->zipVerify();
            if (!$this->zip->extractTo($this->destination)) throw new RuntimeException('Could not extract package archive.');
        } finally {
            $this->zip->close();
        }
    }

getZip

Source line 42

public function getZip(): ZipArchive

Return expressions (including local callbacks): $this->zip.

Implementation, validation guards and interaction order
/**
     * @inheritDoc
     */
    public function getZip(): ZipArchive
    {
        return $this->zip;
    }

getTarget

Source line 50

public function getTarget(): ITransientStorageEntry

Return expressions (including local callbacks): $this->target.

Implementation, validation guards and interaction order
/**
     * @inheritDoc
     */
    public function getTarget(): ITransientStorageEntry
    {
        return $this->target;
    }

getDestination

Source line 58

public function getDestination(): string

Return expressions (including local callbacks): $this->destination.

Implementation, validation guards and interaction order
/**
     * @inheritDoc
     */
    public function getDestination(): string
    {
        return $this->destination;
    }

setTarget

Source line 66

public function setTarget(ITransientStorageEntry $target): void

Parameters

Parameter Type, modifiers and default Purpose
$target ITransientStorageEntry $target Operation input; the exact use, validation and propagation are shown in the implementation trace.

State writes: $this->target.

Implementation, validation guards and interaction order
/**
     * @inheritDoc
     */
    public function setTarget(ITransientStorageEntry $target): void
    {
        $this->target = $target;
    }

setDestination

Source line 74

public function setDestination(string $destination): void

Parameters

Parameter Type, modifiers and default Purpose
$destination string $destination Operation input; the exact use, validation and propagation are shown in the implementation trace.

State writes: $this->destination.

Implementation, validation guards and interaction order
/**
     * @inheritDoc
     */
    public function setDestination(string $destination): void
    {
        $this->destination = $destination;
    }

zipVerify

Source line 82

public function zipVerify(): void

Explicit exceptions: RuntimeException. The guards in the implementation below show when each is raised; exceptions from collaborators also propagate unless caught.

Implementation, validation guards and interaction order
/**
     * @inheritDoc
     */
    public function zipVerify(): void
    {
        if($this->zip->status !== ZipArchive::ER_OK){
            throw new RuntimeException("There was an error extracting the package. ZIP status: {$this->zip->status}");
        }
    }

makeDestination

Source line 92

private function makeDestination(): void

Explicit exceptions: RuntimeException. The guards in the implementation below show when each is raised; exceptions from collaborators also propagate unless caught.

External effects include mkdir.

Implementation, validation guards and interaction order
//Helpers

    private function makeDestination(): void
    {
        if(!is_dir($this->destination) && !mkdir($concurrentDirectory = $this->destination, 0755, true) && !is_dir($concurrentDirectory)) {
            throw new RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
        }
    }

Related types

Clone this wiki locally