Skip to content

Commit 9393cf7

Browse files
committed
Calculate hash properly also taking services' tags into consideration
1 parent a561077 commit 9393cf7

File tree

2 files changed

+56
-8
lines changed

2 files changed

+56
-8
lines changed

src/Symfony/SymfonyContainerResultCacheMetaExtension.php

+21-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use function array_map;
77
use function hash;
88
use function serialize;
9+
use function sort;
910

1011
final class SymfonyContainerResultCacheMetaExtension implements ResultCacheMetaExtension
1112
{
@@ -29,20 +30,32 @@ public function getHash(): string
2930
{
3031
return hash('sha256', serialize([
3132
'parameters' => array_map(
32-
static fn (ParameterDefinition $parameter) => [
33+
static fn (ParameterDefinition $parameter): array => [
3334
'name' => $parameter->getKey(),
3435
'value' => $parameter->getValue(),
3536
],
3637
$this->parameterMap->getParameters(),
3738
),
3839
'services' => array_map(
39-
static fn (ServiceDefinition $service) => [
40-
'id' => $service->getId(),
41-
'class' => $service->getClass(),
42-
'public' => $service->isPublic() ? 'yes' : 'no',
43-
'synthetic' => $service->isSynthetic() ? 'yes' : 'no',
44-
'alias' => $service->getAlias(),
45-
],
40+
static function (ServiceDefinition $service): array {
41+
$serviceTags = array_map(
42+
static fn (ServiceTag $tag) => [
43+
'name' => $tag->getName(),
44+
'attributes' => $tag->getAttributes(),
45+
],
46+
$service->getTags(),
47+
);
48+
sort($serviceTags);
49+
50+
return [
51+
'id' => $service->getId(),
52+
'class' => $service->getClass(),
53+
'public' => $service->isPublic() ? 'yes' : 'no',
54+
'synthetic' => $service->isSynthetic() ? 'yes' : 'no',
55+
'alias' => $service->getAlias(),
56+
'tags' => $serviceTags,
57+
];
58+
},
4659
$this->serviceMap->getServices(),
4760
),
4861
]));

tests/Symfony/SymfonyContainerResultCacheMetaExtensionTest.php

+35
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,41 @@ public static function provideContainerHashIsCalculatedCorrectlyCases(): iterabl
167167
XML,
168168
];
169169

170+
yield 'service tags changes' => [
171+
[
172+
<<<'XML'
173+
<container>
174+
<services>
175+
<service id="Foo" class="Foo">
176+
<tag name="foo.bar" baz="bar"/>
177+
<tag name="foo.baz" baz="baz"/>
178+
</service>
179+
</services>
180+
</container>
181+
XML,
182+
<<<'XML'
183+
<container>
184+
<services>
185+
<service id="Foo" class="Foo">
186+
<tag name="foo.baz" baz="baz"/>
187+
<tag name="foo.bar" baz="bar"/>
188+
</service>
189+
</services>
190+
</container>
191+
XML,
192+
],
193+
<<<'XML'
194+
<container>
195+
<services>
196+
<service id="Foo" class="Foo">
197+
<tag name="foo.bar" baz="bar"/>
198+
<tag name="foo.baz" baz="buzz"/>
199+
</service>
200+
</services>
201+
</container>
202+
XML,
203+
];
204+
170205
yield 'new service added' => [
171206
[
172207
<<<'XML'

0 commit comments

Comments
 (0)