Skip to content

Internals Package Dependency Dependency

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

package\dependency\Dependency

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/package/dependency/Dependency.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.

Dependency

Declaration and architectural role

readonly class Dependency

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 public function __construct(public string $name Initialized from the constructor argument; default expression is evaluated when the argument is omitted.
Constructor-promoted public string $version = '*' Initialized from the constructor argument; default expression is evaluated when the argument is omitted.
Constructor-promoted public string $url = '') Initialized from the constructor argument; default expression is evaluated when the argument is omitted.

Method index

Method Signature
__construct public function __construct(public string $name, public string $version = '*', public string $url = '')
fromArray public static function fromArray(array $data): static
matchesVersion public static function matchesVersion(string $version, string $constraint): bool

__construct

Source line 6

public function __construct(public string $name, public string $version = '*', public string $url = '');

Parameters

Parameter Type, modifiers and default Purpose
$name public string $name Named key/label selected by this API; its exact scope is shown by the implementation trace.
$version public string $version = '*' Operation input; the exact use, validation and propagation are shown in the implementation trace.
$url public string $url = '' 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.

fromArray

Source line 7

public static function fromArray(array $data): static

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): new static($data['name'], $version, $url).

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 fromArray(array $data): static
    {
        if (!isset($data['name']) || !is_string($data['name']) || trim($data['name']) === '') {
            throw new \InvalidArgumentException('Dependencies must specify a package name.');
        }
        $version = $data['version'] ?? '*';
        $url = $data['url'] ?? '';
        if (!is_string($version) || !is_string($url)) throw new \InvalidArgumentException('Dependency version and url must be strings.');
        self::matchesVersion('0.0.0', $version); // Validate even before the dependency is installed.
        return new static($data['name'], $version, $url);
    }

matchesVersion

Source line 19

public static function matchesVersion(string $version, string $constraint): bool

Parameters

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

Exact versions, *, and whitespace-separated comparisons (logical AND).

Return expressions (including local callbacks): true; $matches.

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
/** Exact versions, *, and whitespace-separated comparisons (logical AND). */
    public static function matchesVersion(string $version, string $constraint): bool
    {
        if ($constraint === '*') return true;
        $matches = true;
        foreach (preg_split('/\s+/', trim($constraint)) as $part) {
            if (!preg_match('/^(>=|<=|>|<|==|=|!=)?(\d+(?:\.\d+){0,2}(?:-[0-9A-Za-z.-]+)?)$/', $part, $match)) {
                throw new \InvalidArgumentException("Unsupported dependency version constraint: {$constraint}");
            }
            $matches = version_compare($version, $match[2], ($match[1] ?? '') ?: '==') && $matches;
        }
        return $matches;
    }

Clone this wiki locally