Skip to content

Internals Installer Package PackageAssetLinks

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

installer\package\PackageAssetLinks

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/installer/package/PackageAssetLinks.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 package\facade\PackageFacade;
use vfs\storage\enums\EOwnerType;
use vfs\storage\interfaces\IStorageRepository;
use vfs\storage\StorageEntry;
use vfs\storage\StorageRepository;

PackageAssetLinks

Declaration and architectural role

final readonly class PackageAssetLinks

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 IStorageRepository $storage = new StorageRepository() Initialized from the constructor argument; default expression is evaluated when the argument is omitted.
Constructor-promoted private PackageFacade $packages = new PackageFacade() Initialized from the constructor argument; default expression is evaluated when the argument is omitted.

Method index

Method Signature
__construct public function __construct( private IStorageRepository $storage = new StorageRepository(), private PackageFacade $packages = new PackageFacade(), )
register public function register(int $packageId, string $storageDirectory, array $manifest): void

__construct

Source line 13

public function __construct(
        private IStorageRepository $storage = new StorageRepository(),
        private PackageFacade $packages = new PackageFacade(),
    );

Parameters

Parameter Type, modifiers and default Purpose
$storage private IStorageRepository $storage = new StorageRepository() Operation input; the exact use, validation and propagation are shown in the implementation trace.
$packages private PackageFacade $packages = new PackageFacade() 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.

register

Source line 18

public function register(int $packageId, string $storageDirectory, array $manifest): void

Parameters

Parameter Type, modifiers and default Purpose
$packageId int $packageId Installed package ID used for metadata/schema/storage ownership.
$storageDirectory string $storageDirectory Operation input; the exact use, validation and propagation are shown in the implementation trace.
$manifest array $manifest Operation input; the exact use, validation and propagation are shown in the implementation trace.

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
public function register(int $packageId, string $storageDirectory, array $manifest): void
    {
        $entries = $this->storage->fetchByOwnerTypeAndOwner(EOwnerType::PACKAGE, $packageId);
        $links = [];
        foreach (['icon', 'preview_image'] as $field) {
            $reference = $manifest[$field] ?? null;
            if ($reference === null || $reference === '') continue;

            $path = rtrim($storageDirectory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $reference;
            $matches = array_values(array_filter($entries, static fn(StorageEntry $entry): bool => $entry->getPath() === $path));
            if ($matches === [] && basename($reference) === $reference) {
                $matches = array_values(array_filter($entries, static fn(StorageEntry $entry): bool => $entry->getName() === $reference));
            }
            if (count($matches) > 1) {
                throw new \RuntimeException("Ambiguous package {$field}: {$reference}. Use a path relative to the data directory.");
            }
            if ($matches !== []) $links[$field] = $matches[0]->getUrl();
        }

        if ($links === []) return;

        $package = $this->packages->getPackageById($packageId);
        $changed = false;
        if (isset($links['icon']) && $package->getIcon() !== $links['icon']) {
            $package->setIcon($links['icon']);
            $changed = true;
        }
        if (isset($links['preview_image']) && $package->getPreviewImage() !== $links['preview_image']) {
            $package->setPreviewImage($links['preview_image']);
            $changed = true;
        }
        if ($changed && !$package->save()) {
            throw new \RuntimeException('Failed to persist package asset links.');
        }
    }

Related types

Clone this wiki locally