|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\Symfony; |
| 4 | + |
| 5 | +use PHPStan\Analyser\ResultCache\ResultCacheMetaExtension; |
| 6 | +use function array_map; |
| 7 | +use function hash; |
| 8 | +use function serialize; |
| 9 | + |
| 10 | +final class SymfonyContainerResultCacheMetaExtension implements ResultCacheMetaExtension |
| 11 | +{ |
| 12 | + |
| 13 | + private ParameterMapFactory $parameterMapFactory; |
| 14 | + |
| 15 | + private ServiceMapFactory $serviceMapFactory; |
| 16 | + |
| 17 | + public function __construct( |
| 18 | + ParameterMapFactory $parameterMapFactory, |
| 19 | + ServiceMapFactory $serviceMapFactory |
| 20 | + ) |
| 21 | + { |
| 22 | + $this->parameterMapFactory = $parameterMapFactory; |
| 23 | + $this->serviceMapFactory = $serviceMapFactory; |
| 24 | + } |
| 25 | + |
| 26 | + public function getKey(): string |
| 27 | + { |
| 28 | + return 'symfonyDiContainer'; |
| 29 | + } |
| 30 | + |
| 31 | + public function getHash(): string |
| 32 | + { |
| 33 | + return hash('sha256', serialize([ |
| 34 | + 'parameters' => array_map( |
| 35 | + static fn (ParameterDefinition $parameter) => [ |
| 36 | + 'name' => $parameter->getKey(), |
| 37 | + 'value' => $parameter->getValue(), |
| 38 | + ], |
| 39 | + $this->parameterMapFactory->create()->getParameters(), |
| 40 | + ), |
| 41 | + 'services' => array_map( |
| 42 | + static fn (ServiceDefinition $service) => [ |
| 43 | + 'id' => $service->getId(), |
| 44 | + 'class' => $service->getClass(), |
| 45 | + 'public' => $service->isPublic() ? 'yes' : 'no', |
| 46 | + 'synthetic' => $service->isSynthetic() ? 'yes' : 'no', |
| 47 | + 'alias' => $service->getAlias(), |
| 48 | + ], |
| 49 | + $this->serviceMapFactory->create()->getServices(), |
| 50 | + ), |
| 51 | + ])); |
| 52 | + } |
| 53 | + |
| 54 | +} |
0 commit comments