PackageMetadata
API reference › Foxy › Native › PackageMetadata
Represents the abbreviated npm registry metadata of a package: its dist-tags and its installable versions.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$distTags readonly constructor | array<string, | Dist-tag names mapped to versions. | PackageMetadata |
$name readonly constructor | string | Package name. | PackageMetadata |
$versions readonly constructor | array<string, PackageVersion> | Versions keyed by version string, limited to the versions that Composer’s VersionParser can normalize. | PackageMetadata |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Describes the installable versions returned for an npm package. | PackageMetadata |
fromDocument() static | Creates 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 |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”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
| Parameter | Type | Description |
|---|---|---|
$name | string | Package name. |
$distTags | array<string, | Dist-tag names mapped to versions. |
$versions | array<string, PackageVersion> | Versions keyed by version string, limited to the versions that Composer’s VersionParser can normalize. |
fromDocument()
Section titled “fromDocument() ”public static function fromDocument(string $name, mixed $document): selfCreates 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
| Parameter | Type | Description |
|---|---|---|
$name | string | Package name used in error messages and copied into every version. |
$document | mixed | Registry document decoded as associative arrays. |
Returns
self
Throws
Foxy\Exception\RuntimeException: if the document, its dist-tags, or a normalizable version entry is malformed.
getDistTag()
Section titled “getDistTag() ”public function getDistTag(string $tag): string|nullReturns the version a dist-tag points to, or null when the tag is unknown.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tag | string |
Returns
string|null
getVersion()
Section titled “getVersion() ”public function getVersion(string $version): Foxy\Native\PackageVersion|nullReturns the metadata of a version, or null when the version is unknown.