1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Analyser\ResultCache;
4:
5: use PHPStan\DependencyInjection\ExtensionInterface;
6:
7: /**
8: * A value outside of the analysed code that rules and extensions read - whether a service
9: * exists in a DI container, the value of a configuration parameter, the contents of a file.
10: *
11: * A rule or an extension reading such a value declares it:
12: *
13: * ```php
14: * $scope->trackValueDependency(MyExtension::class, $key);
15: * ```
16: *
17: * The result cache then records the value, and re-analyses the files that declared it when it
18: * is different, and only them. Compared to ResultCacheMetaExtension, which discards the whole
19: * result cache on any change, only what was actually asked about matters, and only for the
20: * files asking.
21: *
22: * To register it in the configuration file use the `phpstan.resultCacheValueExtension` service tag:
23: *
24: * ```
25: * services:
26: * -
27: * class: App\PHPStan\MyExtension
28: * tags:
29: * - phpstan.resultCacheValueExtension
30: * ```
31: *
32: * @api
33: */
34: #[ExtensionInterface(tag: self::EXTENSION_TAG)]
35: interface ResultCacheValueExtension
36: {
37:
38: public const EXTENSION_TAG = 'phpstan.resultCacheValueExtension';
39:
40: /**
41: * The current value for the key - compared with the one recorded by the last analysis.
42: * A long value is better hashed.
43: *
44: * `getValue` is invoked before [`bootstrapFiles`](https://phpstan.org/config-reference#bootstrap) are included.
45: */
46: public function getValue(string $key): string;
47:
48: /**
49: * The key as the result cache stores it. A key that is a file path is best stored relative to
50: * the project, so that the result cache survives a moved checkout.
51: */
52: public function keyToResultCache(string $key): string;
53:
54: /**
55: * The key back from the result cache - the reverse of keyToResultCache().
56: */
57: public function keyFromResultCache(string $storedKey): string;
58:
59: }
60: