-
Notifications
You must be signed in to change notification settings - Fork 568
Expand file tree
/
Copy pathExternalFileDependencyRegistrar.php
More file actions
46 lines (38 loc) · 1.14 KB
/
ExternalFileDependencyRegistrar.php
File metadata and controls
46 lines (38 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php declare(strict_types = 1);
namespace PHPStan\Analyser;
use PHPStan\DependencyInjection\AutowiredService;
use function array_unique;
use function array_values;
/**
* Allows extensions to declare that the currently analyzed file depends on
* an external (non-analyzed) file. When that external file changes, only
* the dependent analyzed files are re-analyzed instead of the entire project.
*
* This is an alternative to ResultCacheMetaExtension for cases where
* external data changes should not cause full cache invalidation.
*
* @api
*/
#[AutowiredService]
final class ExternalFileDependencyRegistrar
{
/** @var list<string> */
private array $currentFileDependencies = [];
/**
* Register a dependency on an external file for the currently analyzed file.
*/
public function add(string $externalFilePath): void
{
$this->currentFileDependencies[] = $externalFilePath;
}
/**
* @return list<string>
* @internal Used by FileAnalyser after each file analysis
*/
public function getAndReset(): array
{
$deps = array_values(array_unique($this->currentFileDependencies));
$this->currentFileDependencies = [];
return $deps;
}
}