# ServiceMapResultCacheValueExtension

> Exposes the Yii configuration values that drive inferred types to the PHPStan result cache.

[API reference](/docs/api/index.md) › [PHPStan](/docs/extensions/phpstan/reference/index.md) › ServiceMapResultCacheValueExtension

| final class | `yii2\extensions\phpstan\ServiceMapResultCacheValueExtension` |
| --- | --- |
| Implements | [`ResultCacheValueExtension`](https://apiref.phpstan.org/2.3.x/PHPStan.Analyser.ResultCache.ResultCacheValueExtension.html) |
| Source | [`src/ServiceMapResultCacheValueExtension.php`](https://github.com/yii2-extensions/phpstan/blob/main/src/ServiceMapResultCacheValueExtension.php#L30) |

Exposes the Yii configuration values that drive inferred types to the PHPStan result cache.

Extensions record a value dependency (`trackValueDependency()`) on one of the keys built by this class whenever they
read the configuration on behalf of analysed code, including when the configuration has no entry for the requested
id. On the next run PHPStan compares [`getValue()`](/docs/extensions/phpstan/reference/servicemapresultcachevalueextension/index.md#method-getValue) with the recorded value and re-analyses only the files whose
values changed, which also covers configuration composed from several files through `require`.

[`ResultCacheValueExtension`](https://apiref.phpstan.org/2.3.x/PHPStan.Analyser.ResultCache.ResultCacheValueExtension.html) for PHPStan result cache value extension contract.
[`ServiceMap`](/docs/extensions/phpstan/reference/servicemap/index.md) for service and component map for Yii Application static analysis.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Initializes configuration value tracking with the configured generic component map. | `ServiceMapResultCacheValueExtension` |
| [`behaviorsKey()`](#method-behaviorsKey) static | Returns the key for the behaviors attached to the given class. | `ServiceMapResultCacheValueExtension` |
| [`componentKey()`](#method-componentKey) static | Returns the key for the application component with the given id. | `ServiceMapResultCacheValueExtension` |
| [`getValue()`](#method-getValue) | Returns the current configuration value for the given key. | `ServiceMapResultCacheValueExtension` |
| [`keyFromResultCache()`](#method-keyFromResultCache) | Returns the key unchanged, since keys hold ids and class names rather than file paths. | `ServiceMapResultCacheValueExtension` |
| [`keyToResultCache()`](#method-keyToResultCache) | Returns the key unchanged, since keys hold ids and class names rather than file paths. | `ServiceMapResultCacheValueExtension` |
| [`serviceKey()`](#method-serviceKey) static | Returns the key for the DI container definition or singleton with the given id. | `ServiceMapResultCacheValueExtension` |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-APPLICATION_KEY"></span>`APPLICATION_KEY` | `'application'` | Key of the configured application class. | `ServiceMapResultCacheValueExtension` |
| <span id="const-MISSING"></span>`MISSING` | `'missing'` | Value returned for keys whose id has no configuration entry. | `ServiceMapResultCacheValueExtension` |
| <span id="const-PARAMS_KEY"></span>`PARAMS_KEY` | `'params'` | Key of the array shape inferred for the application params. | `ServiceMapResultCacheValueExtension` |
| <span id="const-UNRESOLVED"></span>`UNRESOLVED` | `'unresolved'` | Value returned for a component or service defined in the configuration whose class can't be determined. | `ServiceMapResultCacheValueExtension` |
| <span id="const-UNSUPPORTED"></span>`UNSUPPORTED` | `'unsupported'` | Value returned for keys this class doesn't build, such as keys stored by another version of the extension. | `ServiceMapResultCacheValueExtension` |

## Method details

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

```php
public function __construct(yii2\extensions\phpstan\ServiceMap $serviceMap, array<string, string> $genericComponents = [])
```

Initializes configuration value tracking with the configured generic component map.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$serviceMap` | [`ServiceMap`](/docs/extensions/phpstan/reference/servicemap/index.md) | Service and component map for Yii Application static analysis. |
| `$genericComponents` | `array<string, string>` | Map of component id to the definition key holding its generic type argument (`yii2.component_generics`). |

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

```php
public static function behaviorsKey(string $className): string
```

Returns the key for the behaviors attached to the given class.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$className` | `string` | Fully qualified class name the behaviors are configured for. |

**Returns**

`string`

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

```php
public static function componentKey(string $id): string
```

Returns the key for the application component with the given id.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$id` | `string` | Component id. |

**Returns**

`string`

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

```php
public function getValue(string $key): string
```

Returns the current configuration value for the given key.

Each value covers exactly what the extensions derive types from:

- `application`: the configured application class.
- `params`: a hash of the params shape built by [`ParamsTypeBuilder`](/docs/extensions/phpstan/reference/paramstypebuilder/index.md), or [`MISSING`](/docs/extensions/phpstan/reference/servicemapresultcachevalueextension/index.md#const-MISSING) when no params are
  configured.
- `component:<id>`: a hash of the component class and its generic type argument, [`UNRESOLVED`](/docs/extensions/phpstan/reference/servicemapresultcachevalueextension/index.md#const-UNRESOLVED) when the
  component is defined with a class that can't be determined, or [`MISSING`](/docs/extensions/phpstan/reference/servicemapresultcachevalueextension/index.md#const-MISSING).
- `service:<id>`: the configured service class, [`UNRESOLVED`](/docs/extensions/phpstan/reference/servicemapresultcachevalueextension/index.md#const-UNRESOLVED) when the service is defined with a class that
  can't be determined, or [`MISSING`](/docs/extensions/phpstan/reference/servicemapresultcachevalueextension/index.md#const-MISSING).
- `behaviors:<class>`: a hash of the ordered behavior classes, or [`MISSING`](/docs/extensions/phpstan/reference/servicemapresultcachevalueextension/index.md#const-MISSING) when none are attached.

Any other key yields [`UNSUPPORTED`](/docs/extensions/phpstan/reference/servicemapresultcachevalueextension/index.md#const-UNSUPPORTED), so a result cache written by another version of the extension
re-analyses the files depending on it instead of failing the run.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string` | Key built by this class. |

**Returns**

`string`: Value compared with the one recorded by the previous analysis.

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

```php
public function keyFromResultCache(string $storedKey): string
```

Returns the key unchanged, since keys hold ids and class names rather than file paths.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$storedKey` | `string` |  |

**Returns**

`string`

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

```php
public function keyToResultCache(string $key): string
```

Returns the key unchanged, since keys hold ids and class names rather than file paths.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string` |  |

**Returns**

`string`

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

```php
public static function serviceKey(string $id): string
```

Returns the key for the DI container definition or singleton with the given id.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$id` | `string` | Service id. |

**Returns**

`string`