# VersionResolver

> Resolves human-readable Composer package versions for the debug UI.

[API reference](/docs/api/index.md) › [Debug](/docs/extensions/debug/reference/index.md) › VersionResolver

| final class | `yii\debug\VersionResolver` |
| --- | --- |
| Source | [`src/VersionResolver.php`](https://github.com/yii2-extensions/debug/blob/main/src/VersionResolver.php#L20) |

Resolves human-readable Composer package versions for the debug UI.

Replaces Composer's synthetic dev placeholders (`22.0.9999999.9999999-dev`, `dev-master`) with the package alias plus
the short Git reference, producing strings such as `22.x-dev @a1b2c3d` or `2.0.45`.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`forExtensions()`](#method-forExtensions) static | Rewrites the `version` field of each entry with the friendly version, when resolvable. | `VersionResolver` |
| [`forPackage()`](#method-forPackage) static | Returns a friendly version string for a Composer package. | `VersionResolver` |
| [`yii()`](#method-yii) static | Returns the Yii framework version for the toolbar brand chip. | `VersionResolver` |

## Method details

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

```php
public static function forExtensions(array<int|string, array{name?: string, version?: string, bootstrap?: string|array<string, mixed>, alias?: array<string, string>}> $extensions): array<int|string, array{name?: string, version?: string, bootstrap?: string|array<string, mixed>, alias?: array<string, string>}>
```

Rewrites the `version` field of each entry with the friendly version, when resolvable.

Accepts the array shape produced by `Yii::$app->extensions`; `[$packageName => ['name' => ..., 'version' =>
...]]`. Entries whose key is not a string (malformed registrations) or whose package cannot be resolved through
Composer are returned unchanged.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$extensions` | `array<int\|string, array{name?: string, version?: string, bootstrap?: string\|array<string, mixed>, alias?: array<string, string>}>` | Extension map keyed by package name. |

**Returns**

`array<int|string, array{name?: string, version?: string, bootstrap?: string|array<string, mixed>, alias?: array<string, string>}>`: Extension map with `version` fields rewritten in place.

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

```php
public static function forPackage(string $package): string|null
```

Returns a friendly version string for a Composer package.

Tagged releases are returned verbatim. Dev branches are augmented with the 7-character Git short hash so two
builds of the same branch can be told apart.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$package` | `string` | Composer package name (`vendor/package`). |

**Returns**

`string|null`: Friendly version, or `null` when the package is not installed or has no pretty version.

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

```php
public static function yii(): string
```

Returns the Yii framework version for the toolbar brand chip.

**Returns**

`string`: Yii version label for the brand chip.