| 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: | public function getValue(string $key): string; |
| 45: | |
| 46: | /** |
| 47: | * The key as the result cache stores it. A key that is a file path is best stored relative to |
| 48: | * the project, so that the result cache survives a moved checkout. |
| 49: | */ |
| 50: | public function keyToResultCache(string $key): string; |
| 51: | |
| 52: | /** |
| 53: | * The key back from the result cache - the reverse of keyToResultCache(). |
| 54: | */ |
| 55: | public function keyFromResultCache(string $storedKey): string; |
| 56: | |
| 57: | } |
| 58: |