Skip to content

Internals Uninstaller PackageUninstaller

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

uninstaller\PackageUninstaller

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/uninstaller/PackageUninstaller.php · Snapshot 8411f4287706.

Uninstallation deletes the package record before attempting each cleanup collaborator. Failures are collected; cleanup continues and can leave partial state.

Imports and dependencies

use database\creator\table\TableRegistry;
use database\creator\table\TableSchemaProvider;
use database\DatabaseManager;
use database\provider\DatabaseProvider;
use package\facade\PackageFacade;
use uninstaller\cleanup\PackageFilesCleanup;
use uninstaller\cleanup\ResourceCleanup;
use uninstaller\cleanup\StorageCleanup;
use uninstaller\cleanup\TableCleanup;
use uninstaller\interfaces\IPackageCleanup;
use uninstaller\interfaces\IPackageUninstaller;
use vfs\storage\services\LocalFileSystemService;
use vfs\storage\StorageRepository;

PackageUninstaller

Declaration and architectural role

class PackageUninstaller implements IPackageUninstaller

Source description (behavioral corrections are recorded in Known discrepancies):

Self-wiring facade. Package and dependency records are left to the caller. Every cleanup is attempted; false means getErrors() contains failures.

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
$errors private array $errors = []; Used by uninstall(), getErrors().
$steps private array $steps; Used by __construct(), uninstall().
$packageFacade private PackageFacade $packageFacade; Used by __construct(), uninstall().

Method index

Method Signature
__construct public function __construct( ?array $steps = null, ?PackageFacade $packageFacade = null, string $packageRoot = PACKAGES, )
uninstall public function uninstall(int $id): bool
getErrors public function getErrors(): array

__construct

Source line 32

public function __construct(
        ?array $steps = null,
        ?PackageFacade $packageFacade = null,
        string $packageRoot = PACKAGES,
    )

Parameters

Parameter Type, modifiers and default Purpose
$steps ?array $steps = null Override or extend cleanup collaborators.
$packageFacade ?PackageFacade $packageFacade = null Operation input; the exact use, validation and propagation are shown in the implementation trace.
$packageRoot string $packageRoot = PACKAGES Operation input; the exact use, validation and propagation are shown in the implementation trace.

@param IPackageCleanup[]|null $steps Override or extend cleanup collaborators.

State writes: $this->packageFacade, $this->steps.

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

Implementation, validation guards and interaction order
/**
     * @param IPackageCleanup[]|null $steps Override or extend cleanup collaborators.
     */
    public function __construct(
        ?array $steps = null,
        ?PackageFacade $packageFacade = null,
        string $packageRoot = PACKAGES,
    ) {
        $this->packageFacade = $packageFacade ?? new PackageFacade();
        $this->steps = $steps ?? [
            new StorageCleanup(new StorageRepository(), new LocalFileSystemService()),
            new PackageFilesCleanup($packageRoot),
            new ResourceCleanup($packageRoot),
            new TableCleanup(new TableRegistry(new DatabaseManager()), new TableSchemaProvider(new DatabaseProvider())),
        ];
        foreach ($this->steps as $step) {
            if (!$step instanceof IPackageCleanup) {
                throw new \InvalidArgumentException('Cleanup steps must implement IPackageCleanup.');
            }
        }
    }

uninstall

Source line 51

public function uninstall(int $id): bool

Parameters

Parameter Type, modifiers and default Purpose
$id int $id Record or runtime identifier selected by this operation.

State writes: $this->errors, $this->errors[].

Return expressions (including local callbacks): false; $this->errors === [].

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

Failure handling catches \Throwable.

Implementation, validation guards and interaction order
public function uninstall(int $id): bool
    {
        $this->errors = [];
        try {
            if ($id <= 0) {
                throw new \InvalidArgumentException('Package ID must be positive.');
            }
            $package = $this->packageFacade->getPackageById($id);
            $name = $package->getName();
            if ($name === '' || $name === '.' || $name === '..' || strpbrk($name, "/\\\0") !== false) {
                throw new \InvalidArgumentException('Invalid package directory name.');
            }
            if (!$package->deleteModel()) throw new \RuntimeException('Failed to delete package record.');
        } catch (\Throwable $error) {
            $this->errors[] = 'Package lookup: ' . $error->getMessage();
            return false;
        }

        foreach ($this->steps as $step) {
            try {
                foreach ($step->clean($id, $name) as $error) {
                    $this->errors[] = get_class($step) . ': ' . $error;
                }
            } catch (\Throwable $error) {
                $this->errors[] = get_class($step) . ': ' . $error->getMessage();
            }
        }


        return $this->errors === [];
    }

getErrors

Source line 83

public function getErrors(): array

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

Implementation, validation guards and interaction order
public function getErrors(): array
    {
        return $this->errors;
    }

Related types

Clone this wiki locally