Skip to content
PHP Ecosystem
Explore

ServiceMapResultCacheValueExtension

API reference › PHPStan › ServiceMapResultCacheValueExtension

final classyii2\extensions\phpstan\ServiceMapResultCacheValueExtension
ImplementsResultCacheValueExtension
Sourcesrc/ServiceMapResultCacheValueExtension.php

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() with the recorded value and re-analyses only the files whose values changed, which also covers configuration composed from several files through require.

ResultCacheValueExtension for PHPStan result cache value extension contract. ServiceMap for service and component map for Yii Application static analysis.

MethodDescriptionDefined by
__construct()Initializes configuration value tracking with the configured generic component map.ServiceMapResultCacheValueExtension
behaviorsKey() staticReturns the key for the behaviors attached to the given class.ServiceMapResultCacheValueExtension
componentKey() staticReturns the key for the application component with the given id.ServiceMapResultCacheValueExtension
getValue()Returns the current configuration value for the given key.ServiceMapResultCacheValueExtension
keyFromResultCache()Returns the key unchanged, since keys hold ids and class names rather than file paths.ServiceMapResultCacheValueExtension
keyToResultCache()Returns the key unchanged, since keys hold ids and class names rather than file paths.ServiceMapResultCacheValueExtension
serviceKey() staticReturns the key for the DI container definition or singleton with the given id.ServiceMapResultCacheValueExtension
ConstantValueDescriptionDefined by
APPLICATION_KEY'application'Key of the configured application class.ServiceMapResultCacheValueExtension
MISSING'missing'Value returned for keys whose id has no configuration entry.ServiceMapResultCacheValueExtension
PARAMS_KEY'params'Key of the array shape inferred for the application params.ServiceMapResultCacheValueExtension
UNRESOLVED'unresolved'Value returned for a component or service defined in the configuration whose class can’t be determined.ServiceMapResultCacheValueExtension
UNSUPPORTED'unsupported'Value returned for keys this class doesn’t build, such as keys stored by another version of the extension.ServiceMapResultCacheValueExtension
public function __construct(yii2\extensions\phpstan\ServiceMap $serviceMap, array<string, string> $genericComponents = [])

Initializes configuration value tracking with the configured generic component map.

Parameters

ParameterTypeDescription
$serviceMapServiceMapService and component map for Yii Application static analysis.
$genericComponentsarray<string, string>Map of component id to the definition key holding its generic type argument (yii2.component_generics).
public static function behaviorsKey(string $className): string

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

Parameters

ParameterTypeDescription
$classNamestringFully qualified class name the behaviors are configured for.

Returns

string

public static function componentKey(string $id): string

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

Parameters

ParameterTypeDescription
$idstringComponent id.

Returns

string

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, or MISSING when no params are configured.
  • component:<id>: a hash of the component class and its generic type argument, UNRESOLVED when the component is defined with a class that can’t be determined, or MISSING.
  • service:<id>: the configured service class, UNRESOLVED when the service is defined with a class that can’t be determined, or MISSING.
  • behaviors:<class>: a hash of the ordered behavior classes, or MISSING when none are attached.

Any other key yields 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

ParameterTypeDescription
$keystringKey built by this class.

Returns

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

public function keyFromResultCache(string $storedKey): string

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

Parameters

ParameterTypeDescription
$storedKeystring

Returns

string

public function keyToResultCache(string $key): string

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

Parameters

ParameterTypeDescription
$keystring

Returns

string

public static function serviceKey(string $id): string

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

Parameters

ParameterTypeDescription
$idstringService id.

Returns

string