# LockFile

> Reads and writes foxy.lock: the requirements fingerprint and the packages installed by the native manager.

[API reference](/docs/api/index.md) › [Foxy](/docs/extensions/foxy/reference/index.md) › [Native](/docs/extensions/foxy/reference/native/index.md) › LockFile

| final readonly class | `Foxy\Native\LockFile` |
| --- | --- |
| Source | [`src/Native/LockFile.php`](https://github.com/php-forge/foxy/blob/main/src/Native/LockFile.php#L33) |

Reads and writes `foxy.lock`: the requirements fingerprint and the packages installed by the native manager.

The fingerprint maps each source (`''` for the root manifest, the local package name otherwise) to its mandatory
`dependencies` and its `optionalDependencies`, plus the `version` of a local package, so moving a requirement
between the two kinds or changing a local version makes the lock stale.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates a native dependency lock-file store. | `LockFile` |
| [`exists()`](#method-exists) | Returns whether the lock file exists. | `LockFile` |
| [`read()`](#method-read) | Returns the requirements fingerprint and the locked packages. | `LockFile` |
| [`write()`](#method-write) | Writes the lock file with its maps sorted by key as strings. | `LockFile` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(string $path)
```

Creates a native dependency lock-file store.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$path` | `string` | Lock file path. |

### exists() <span id="method-exists"></span>

```php
public function exists(): bool
```

Returns whether the lock file exists.

**Returns**

`bool`

### read() <span id="method-read"></span>

```php
public function read(): array{requirements: Foxy\Native\Fingerprint, packages: array<array-key, Foxy\Native\ResolvedPackage>}
```

Returns the requirements fingerprint and the locked packages.

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

**Returns**

`array{requirements: Foxy\Native\Fingerprint, packages: array<array-key,` [`ResolvedPackage`](/docs/extensions/foxy/reference/native/resolvedpackage/index.md)`>}`

**Throws**

- [`Foxy\Exception\RuntimeException`](/docs/extensions/foxy/reference/exception/runtimeexception/index.md): if the file is not valid JSON, does not have the lock file shape, or keys a requirement or a package by an invalid package name.

### write() <span id="method-write"></span>

```php
public function write(Foxy\Native\Fingerprint $requirements, array<array-key, Foxy\Native\ResolvedPackage> $packages): void
```

Writes the lock file with its maps sorted by key as strings.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$requirements` | `Foxy\Native\Fingerprint` | Specifications keyed by source (`''` for the root manifest, the local package name otherwise), then by kind, then by package name; a local source also carries its `version`, written first. |
| `$packages` | `array<array-key,` [`ResolvedPackage`](/docs/extensions/foxy/reference/native/resolvedpackage/index.md)`>` | Packages keyed by name. |