Skip to content

Internals Package Model Service PackageService

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

package\model\service\PackageService

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/package/model/service/PackageService.php · Snapshot 8411f4287706.

Package metadata is persisted in awt_package. Manifest readers validate input and package services build installed models; startup executes enabled nonzero-type packages.

Imports and dependencies

use package\model\InstalledPackage;
use package\model\repository\interfaces\IPackageRepository;
use package\model\service\interface\IPackageService;

PackageService

Declaration and architectural role

class PackageService implements IPackageService

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 readonly IPackageRepository $repository Initialized from the constructor argument; default expression is evaluated when the argument is omitted.

Method index

Method Signature
__construct public function __construct( private readonly IPackageRepository $repository )
getActive public function getActive(): array
getDisabled public function getDisabled(): array
getInstalled public function getInstalled(): array
getPackage public function getPackage(string $name): ?InstalledPackage
getPackageById public function getPackageById(int $id): ?InstalledPackage
enablePackage public function enablePackage(int $id): void
disablePackage public function disablePackage(int $id): void
setStatus private function setStatus(int $id, bool $status): void
mapPackages private function mapPackages(array $data): array
mapPackage private function mapPackage(array $data): InstalledPackage

__construct

Source line 11

public function __construct(
        private readonly IPackageRepository $repository
    );

Parameters

Parameter Type, modifiers and default Purpose
$repository private readonly IPackageRepository $repository 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.

getActive

Source line 16

public function getActive(): array

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

Implementation, validation guards and interaction order
public function getActive(): array
    {
        $res = $this->repository->getActive();
        return $this->mapPackages($res);
    }

getDisabled

Source line 22

public function getDisabled(): array

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

Implementation, validation guards and interaction order
public function getDisabled(): array
    {
        $res = $this->repository->getDisabled();
        return $this->mapPackages($res);
    }

getInstalled

Source line 29

public function getInstalled(): array

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

Implementation, validation guards and interaction order
public function getInstalled(): array
    {
        $res = $this->repository->getAll();
        return $this->mapPackages($res);
    }

getPackage

Source line 35

public function getPackage(string $name): ?InstalledPackage

Parameters

Parameter Type, modifiers and default Purpose
$name string $name Named key/label selected by this API; its exact scope is shown by the implementation trace.

Return expressions (including local callbacks): null; $this->mapPackage($res).

Implementation, validation guards and interaction order
public function getPackage(string $name): ?InstalledPackage
    {
        $res = $this->repository->getPackage($name);

        if (!$res) return null;

        return $this->mapPackage($res);
    }

getPackageById

Source line 44

public function getPackageById(int $id): ?InstalledPackage

Parameters

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

Return expressions (including local callbacks): $data === null ? null : $this->mapPackage($data).

Implementation, validation guards and interaction order
public function getPackageById(int $id): ?InstalledPackage
    {
        $data = $this->repository->getPackageById($id);
        return $data === null ? null : $this->mapPackage($data);
    }

enablePackage

Source line 50

public function enablePackage(int $id): void

Parameters

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

Delegates to setStatus().

Implementation, validation guards and interaction order
public function enablePackage(int $id): void { $this->setStatus($id, true); }

disablePackage

Source line 51

public function disablePackage(int $id): void

Parameters

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

Delegates to setStatus().

Implementation, validation guards and interaction order
public function disablePackage(int $id): void { $this->setStatus($id, false); }

setStatus

Source line 53

private function setStatus(int $id, bool $status): void

Parameters

Parameter Type, modifiers and default Purpose
$id int $id Record or runtime identifier selected by this operation.
$status bool $status Operation input; the exact use, validation and propagation are shown in the implementation trace.

Explicit exceptions: \OutOfBoundsException, \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
private function setStatus(int $id, bool $status): void
    {
        $package = $this->repository->getPackageById($id);
        if ($package === null) {
            throw new \OutOfBoundsException("Package with ID {$id} not found.");
        }
        if ((bool) $package['status'] === $status) return;
        if (!$this->repository->setStatus($id, $status)) {
            throw new \RuntimeException('Failed to persist package status.');
        }
    }

mapPackages

Source line 65

private function mapPackages(array $data): array

Parameters

Parameter Type, modifiers and default Purpose
$data array $data Input data array or payload; see allowed fields and validation guards below.

Return expressions (including local callbacks): array_map(fn($item) => $this->mapPackage($item), $data).

Implementation, validation guards and interaction order
private function mapPackages(array $data): array
    {
        return array_map(fn($item) => $this->mapPackage($item), $data);
    }

mapPackage

Source line 70

private function mapPackage(array $data): InstalledPackage

Parameters

Parameter Type, modifiers and default Purpose
$data array $data Input data array or payload; see allowed fields and validation guards below.

Return expressions (including local callbacks): $package.

Implementation, validation guards and interaction order
private function mapPackage(array $data): InstalledPackage
    {
        $package = new InstalledPackage();
        $data['dependencies'] = $data['dependencies'] ?? [];
        if ($this->repository instanceof \database\DatabaseManager) {
            $package->useConnectionFrom($this->repository);
        }
        $package->hydrateRow($data, 'awt_package', 'id');
        $package->createDependencyCollection();
        return $package;
    }

Related types

Clone this wiki locally