Repository navigation
Internals 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.
use package\model\InstalledPackage;
use package\model\repository\interfaces\IPackageRepository;
use package\model\service\interface\IPackageService;class PackageService implements IPackageServiceDeclarations 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 | 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 |
public function __construct(
private readonly IPackageRepository $repository
);| 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.
public function getActive(): arrayReturn 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);
}public function getDisabled(): arrayReturn 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);
}public function getInstalled(): arrayReturn 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);
}public function getPackage(string $name): ?InstalledPackage| 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);
}public function getPackageById(int $id): ?InstalledPackage| 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);
}public function enablePackage(int $id): void| 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); }public function disablePackage(int $id): void| 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); }private function setStatus(int $id, bool $status): void| 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.');
}
}private function mapPackages(array $data): array| 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);
}private function mapPackage(array $data): InstalledPackage| 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;
}AWT Framework Wiki · Home · Installation Guide · Developer Guide · Framework Internals
Philosophy · Architecture · Known discrepancies · Verification
Installation Guide
Developer Guide
- Learning sequence
- First package
- Package structure
- Lifecycle
- Runtimes
- Events and objects
- Routing and controllers
- Views and resources
- Database and models
- Storage and caching
- Configuration and CLI
- Responses and errors
- Extension points
Framework Internals
- Architecture
- Bootstrap
- Packages
- Runtime
- Events and context
- Objects
- HTTP routing and controllers
- Rendering
- Blade integration
- Database
- Models
- Storage and caching
- Settings
- CLI
- Identity and sessions
- Responses
- Errors
- Complete source inventory
Documentation notes