Skip to content

Internals Installer Package PackageMover

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

installer\package\PackageMover

Framework Internals · Subsystem overview · Developer guide

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

PackageMover

Declaration and architectural role

class PackageMover implements IPackageMover

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
$source private string $source; Used by __construct(), move(), getSource(), setSource(), scanDirectory().
$destination private string $destination; Used by __construct(), move(), getDestination(), setDestination().
$scanned private array $scanned; Used by __construct(), move(), scanDirectory().
Constructor-promoted public function __construct(string $source Initialized from the constructor argument; default expression is evaluated when the argument is omitted.

Method index

Method Signature
__construct public function __construct(string $source, string $destination)
move public function move(): void
getSource public function getSource(): string
getDestination public function getDestination(): string
setSource public function setSource(string $source): void
setDestination public function setDestination(string $destination): void
scanDirectory private function scanDirectory(string $dir): void

__construct

Source line 15

public function __construct(string $source, string $destination)

Parameters

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

State writes: $this->source, $this->destination, $this->scanned.

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

move

Source line 28

public function move(): void

State writes: $this->scanned.

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, rename, rmdir.

Implementation, validation guards and interaction order
/**
     * @inheritDoc
     */
    public function move(): void
    {
        if (!is_dir($this->source)) {
            throw new RuntimeException("Source directory does not exist: {$this->source}");
        }

        if (!is_dir($this->destination)) {
            throw new RuntimeException("Destination directory does not exist: {$this->destination}");
        }

        $this->scanned = ['directories' => [], 'files' => []];
        $this->scanDirectory($this->source);

        foreach ($this->scanned["directories"] as $dir) {
            $destDir = $this->destination . DIRECTORY_SEPARATOR . $dir;
            if (!is_dir($destDir) && !mkdir($destDir, 0755, true) && !is_dir($destDir)) {
                throw new RuntimeException("Failed to create directory: {$destDir}");
            }
        }

        foreach ($this->scanned["files"] as $file) {
            $srcFile = $this->source . DIRECTORY_SEPARATOR . $file;
            $destFile = $this->destination . DIRECTORY_SEPARATOR . $file;
            if (!rename($srcFile, $destFile)) {
                throw new RuntimeException("Failed to move file from {$srcFile} to {$destFile}");
            }
        }

        foreach (array_reverse($this->scanned["directories"]) as $dir) {
            rmdir($this->source . DIRECTORY_SEPARATOR . $dir);
        }
        rmdir($this->source);
    }

getSource

Source line 65

public function getSource(): string

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

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

getDestination

Source line 73

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;
    }

setSource

Source line 81

public function setSource(string $source): void

Parameters

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

State writes: $this->source.

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

setDestination

Source line 89

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;
    }

scanDirectory

Source line 96

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
//Helper
    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->source) + 1);

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

Related types

Clone this wiki locally