forked from phpstan/phpstan-symfony
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSymfonyContainerResultCacheMetaExtension.php
62 lines (49 loc) · 1.47 KB
/
SymfonyContainerResultCacheMetaExtension.php
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php declare(strict_types = 1);
namespace PHPStan\Symfony;
use PHPStan\Analyser\ResultCache\ResultCacheMetaExtension;
use function array_map;
use function hash;
use function ksort;
use function sort;
use function var_export;
final class SymfonyContainerResultCacheMetaExtension implements ResultCacheMetaExtension
{
private ParameterMap $parameterMap;
private ServiceMap $serviceMap;
public function __construct(ParameterMap $parameterMap, ServiceMap $serviceMap)
{
$this->parameterMap = $parameterMap;
$this->serviceMap = $serviceMap;
}
public function getKey(): string
{
return 'symfonyDiContainer';
}
public function getHash(): string
{
$services = $parameters = [];
foreach ($this->parameterMap->getParameters() as $parameter) {
$parameters[$parameter->getKey()] = $parameter->getValue();
}
ksort($parameters);
foreach ($this->serviceMap->getServices() as $service) {
$serviceTags = array_map(
static fn (ServiceTag $tag) => [
'name' => $tag->getName(),
'attributes' => $tag->getAttributes(),
],
$service->getTags(),
);
sort($serviceTags);
$services[$service->getId()] = [
'class' => $service->getClass(),
'public' => $service->isPublic() ? 'yes' : 'no',
'synthetic' => $service->isSynthetic() ? 'yes' : 'no',
'alias' => $service->getAlias(),
'tags' => $serviceTags,
];
}
ksort($services);
return hash('sha256', var_export(['parameters' => $parameters, 'services' => $services], true));
}
}