Skip to content

Internals Installer Package VerifyStructure

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

installer\package\VerifyStructure

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/installer/package/VerifyStructure.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\IVerifyStructure;
use RuntimeException;

VerifyStructure

Declaration and architectural role

class VerifyStructure implements IVerifyStructure

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
$required private array $required; Used by addFile(), addDirectory(), verify().
$scanned private array $scanned; Used by __construct(), verify(), scanDirectory().
Constructor-promoted private readonly string $root Initialized from the constructor argument; default expression is evaluated when the argument is omitted.

Method index

Method Signature
__construct public function __construct( private readonly string $root )
addFile public function addFile(string $file): IVerifyStructure
addDirectory public function addDirectory(string $dir): IVerifyStructure
verify public function verify(): bool
generateStructure private function generateStructure(): void
scanDirectory private function scanDirectory(string $dir): void

__construct

Source line 14

public function __construct(
        private readonly string $root
    )

Parameters

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

State writes: $this->scanned.

Implementation, validation guards and interaction order
public function __construct(
        private readonly string $root
    ){
        $this->scanned = [
            "directories" => [],
            "files" => []
        ];
    }

addFile

Source line 26

public function addFile(string $file): IVerifyStructure

Parameters

Parameter Type, modifiers and default Purpose
$file string $file Uploaded file array, file object or path according to the declared contract.

State writes: $this->required["files"][].

Return expressions (including local callbacks): $this.

Implementation, validation guards and interaction order
/**
     * @inheritDoc
     */
    public function addFile(string $file): IVerifyStructure
    {
        $this->required["files"][] = $file;
        return $this;
    }

addDirectory

Source line 35

public function addDirectory(string $dir): IVerifyStructure

Parameters

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

State writes: $this->required["directories"][].

Return expressions (including local callbacks): $this.

Implementation, validation guards and interaction order
/**
     * @inheritDoc
     */
    public function addDirectory(string $dir): IVerifyStructure
    {
        $this->required["directories"][] = $dir;
        return $this;
    }

verify

Source line 44

public function verify(): bool

Return expressions (including local callbacks): false; true.

Implementation, validation guards and interaction order
/**
     * @inheritDoc
     */
    public function verify(): bool
    {
        $this->generateStructure();

        foreach ($this->required["files"] ?? [] as $file) {
            if (!in_array($file, $this->scanned["files"], true)
                || !is_readable($this->root . DIRECTORY_SEPARATOR . $file)) {
                return false;
            }
        }

        foreach ($this->required["directories"] ?? [] as $dir) {
            if (!in_array($dir, $this->scanned["directories"], true)) {
                return false;
            }
        }

        return true;
    }

generateStructure

Source line 66

private function generateStructure(): 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
//Helper function

    private function generateStructure(): void
    {
        if(!is_dir($this->root)) {
            throw new RuntimeException("Root directory of the package does not exist. $this->root");
        }

        $this->scanDirectory($this->root);

    }

scanDirectory

Source line 77

private function scanDirectory(string $dir): void

Parameters

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

State writes: $this->scanned["directories"][], $this->scanned["files"][].

Implementation, validation guards and interaction order
private function scanDirectory(string $dir): void
    {
        $scan = scandir($dir);
        unset($scan[0], $scan[1]);

        foreach($scan as $entry) {
            $fullPath = $dir . DIRECTORY_SEPARATOR . $entry;
            $relativePath = substr($fullPath, strlen($this->root) + 1);

            if(is_dir($fullPath)) {
                $this->scanned["directories"][] = $relativePath;
                $this->scanDirectory($fullPath);
            } else {
                $this->scanned["files"][] = $relativePath;
            }
        }
    }

Related types

Clone this wiki locally