Skip to content

Internals Package Manifest Reader ManifestReader

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

package\manifest\reader\ManifestReader

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/package/manifest/reader/ManifestReader.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\dependency\Dependency;
use package\manifest\exceptions\ManifestReaderException;
use package\manifest\reader\interfaces\IManifestReader;

ManifestReader

Declaration and architectural role

readonly class ManifestReader implements IManifestReader

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
$package public string $package; Used by __construct().
$manifestPath private string $manifestPath; Used by __construct(), getManifest().
Constructor-promoted public function __construct(string $package) Initialized from the constructor argument; default expression is evaluated when the argument is omitted.

Method index

Method Signature
__construct public function __construct(string $package)
getManifest public function getManifest(): array
readFile public static function readFile(string $path): array
validate public static function validate(mixed $manifest): array

__construct

Source line 10

public function __construct(string $package)

Parameters

Parameter Type, modifiers and default Purpose
$package string $package Package identifier or InstalledPackage metadata as indicated by the declared type.

State writes: $this->package, $this->manifestPath.

Explicit exceptions: ManifestReaderException. 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 __construct(string $package)
    {
        $this->package = $package;
        $this->manifestPath = PACKAGES . str_replace(' ', '', $package) . '/manifest.json';
        if (!is_file($this->manifestPath)) throw new ManifestReaderException($package, $this->manifestPath);
    }

getManifest

Source line 16

public function getManifest(): array

Return expressions (including local callbacks): self::readFile($this->manifestPath).

Implementation, validation guards and interaction order
public function getManifest(): array
    {
        return self::readFile($this->manifestPath);
    }

readFile

Source line 20

public static function readFile(string $path): array

Parameters

Parameter Type, modifiers and default Purpose
$path string $path Filesystem or route path as defined by the owning component; no universal path normalization is implied.

Return expressions (including local callbacks): self::validate($manifest).

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

Failure handling catches \JsonException.

Implementation, validation guards and interaction order
public static function readFile(string $path): array
    {
        $json = file_get_contents($path);
        if ($json === false) throw new \RuntimeException("Cannot read package manifest: {$path}");
        if (str_starts_with($json, "\xEF\xBB\xBF")) $json = substr($json, 3);
        try {
            $manifest = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
        } catch (\JsonException $error) {
            throw new \JsonException("Invalid JSON in package manifest {$path}: " . $error->getMessage(), $error->getCode(), $error);
        }
        return self::validate($manifest);
    }

validate

Source line 32

public static function validate(mixed $manifest): array

Parameters

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

Return expressions (including local callbacks): $manifest.

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
public static function validate(mixed $manifest): array
    {
        if (!is_array($manifest)) throw new \InvalidArgumentException('Manifest must be a JSON object.');
        foreach (['name', 'version', 'minimum_awt_version'] as $key) {
            if (!isset($manifest[$key]) || !is_string($manifest[$key]) || $manifest[$key] === '') {
                throw new \InvalidArgumentException("Manifest requires string {$key}.");
            }
        }
        foreach (['version', 'minimum_awt_version', 'maximum_awt_version'] as $key) {
            if (isset($manifest[$key]) && (!is_string($manifest[$key]) || !preg_match('/^\d+(?:\.\d+){0,2}(?:-[0-9A-Za-z.-]+)?$/', $manifest[$key]))) {
                throw new \InvalidArgumentException("Invalid manifest version: {$key}");
            }
        }
        if (!preg_match('/^[A-Za-z0-9][A-Za-z0-9 _-]*$/', $manifest['name'])) {
            throw new \InvalidArgumentException('Invalid package name.');
        }
        if (!isset($manifest['type']) || !is_int($manifest['type']) || !in_array($manifest['type'], [0, 1, 2], true)) {
            throw new \InvalidArgumentException('Manifest type must be 0, 1, or 2.');
        }
        if (!isset($manifest['dependencies']) || !is_array($manifest['dependencies']) || !array_is_list($manifest['dependencies'])) {
            throw new \InvalidArgumentException('Manifest dependencies must be a list.');
        }
        $seen = [];
        foreach ($manifest['dependencies'] as $data) {
            if (!is_array($data)) throw new \InvalidArgumentException('Dependencies must be objects.');
            $dependency = Dependency::fromArray($data);
            if ($dependency->name === $manifest['name'] || isset($seen[$dependency->name])) {
                throw new \InvalidArgumentException('Self or duplicate dependency: ' . $dependency->name);
            }
            $seen[$dependency->name] = true;
        }
        foreach (['maximum_awt_version', 'author', 'description', 'icon', 'preview_image', 'license', 'license_url'] as $key) {
            if (isset($manifest[$key]) && !is_string($manifest[$key])) throw new \InvalidArgumentException("Manifest {$key} must be a string or null.");
        }
        if (isset($manifest['system_package']) && !is_bool($manifest['system_package']) && !in_array($manifest['system_package'], [0, 1], true)) {
            throw new \InvalidArgumentException('Manifest system_package must be boolean or 0/1.');
        }
        return $manifest;
    }

Related types

Clone this wiki locally