Skip to content
PHP Ecosystem
Explore

InstalledState

API reference › Foxy › Native › InstalledState

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

Reads and writes the hidden state file of an install directory: the lock entry of every package the last successful native installation left in place, the counterpart of npm’s node_modules/.package-lock.json.

The state is a cache: a missing or malformed file reads as empty, so the installer extracts every registry package again.

MethodDescriptionDefined by
__construct()Creates an installed-state store for one native install directory.InstalledState
read()Returns the recorded lock entries keyed by package name, in the shape of ResolvedPackage::toLock().InstalledState
write()Writes the state file as {"packages": {...}}, with the names sorted byte-wise.InstalledState
public function __construct(string $path, Composer\IO\IOInterface $io)

Creates an installed-state store for one native install directory.

Parameters

ParameterTypeDescription
$pathstringState file path.
$ioComposer\IO\IOInterfaceOutput for the verbose notice of a malformed file.
public function read(): array<array-key, array<string, string>>

Returns the recorded lock entries keyed by package name, in the shape of ResolvedPackage::toLock().

A missing file reads as empty. A file that is not valid JSON, has no packages map, or holds an entry of another shape also reads as empty, with a verbose warning.

Keys are package names; PHP stores a numeric name such as 123 as an int key.

Returns

array<array-key, array<string, string>>

public function write(array<array-key, array<string, string>> $entries): void

Writes the state file as {"packages": {...}}, with the names sorted byte-wise.

Parameters

ParameterTypeDescription
$entriesarray<array-key, array<string, string>>Lock entries keyed by package name.