Skip to content
PHP Ecosystem
Explore

PackageMetadata

API reference › Foxy › Native › PackageMetadata

final readonly classFoxy\Native\PackageMetadata
Sourcesrc/Native/PackageMetadata.php

Represents the abbreviated npm registry metadata of a package: its dist-tags and its installable versions.

PropertyTypeDescriptionDefined by
$distTags readonly constructorarray<string, string>Dist-tag names mapped to versions.PackageMetadata
$name readonly constructorstringPackage name.PackageMetadata
$versions readonly constructorarray<string, PackageVersion>Versions keyed by version string, limited to the versions that Composer’s VersionParser can normalize.PackageMetadata
MethodDescriptionDefined by
__construct()Describes the installable versions returned for an npm package.PackageMetadata
fromDocument() staticCreates the metadata from a decoded registry document.PackageMetadata
getDistTag()Returns the version a dist-tag points to, or null when the tag is unknown.PackageMetadata
getVersion()Returns the metadata of a version, or null when the version is unknown.PackageMetadata
public function __construct(string $name, array<string, string> $distTags, array<string, Foxy\Native\PackageVersion> $versions)

Describes the installable versions returned for an npm package.

Parameters

ParameterTypeDescription
$namestringPackage name.
$distTagsarray<string, string>Dist-tag names mapped to versions.
$versionsarray<string, PackageVersion>Versions keyed by version string, limited to the versions that Composer’s VersionParser can normalize.
public static function fromDocument(string $name, mixed $document): self

Creates the metadata from a decoded registry document.

Versions whose key cannot be normalized by Composer’s VersionParser are skipped without validation; the entry’s own version field is not consulted. dist.integrity is preferred; a 40-character lowercase hex dist.shasum yields a sha1- integrity value instead.

Parameters

ParameterTypeDescription
$namestringPackage name used in error messages and copied into every version.
$documentmixedRegistry document decoded as associative arrays.

Returns

self

Throws

public function getDistTag(string $tag): string|null

Returns the version a dist-tag points to, or null when the tag is unknown.

Parameters

ParameterTypeDescription
$tagstring

Returns

string|null

public function getVersion(string $version): Foxy\Native\PackageVersion|null

Returns the metadata of a version, or null when the version is unknown.

Parameters

ParameterTypeDescription
$versionstring

Returns

PackageVersion|null