Skip to content

Commit efdc35c

Browse files
committed
feature #33540 [Serializer] Add special '*' serialization group that allows any group (nrobinaubertin)
This PR was squashed before being merged into the 5.2-dev branch. Discussion ---------- [Serializer] Add special '*' serialization group that allows any group | Q | A | ------------- | --- | Branch? | master for features | Bug fix? | no | New feature? | yes | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32622 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Hi, I added support for a special serialization group: '*'. This group lets any group serialize the attribute marked with it. The BC break comes from the fact that someone could have used the '*' group in their code. Commits ------- 54e24a8 [Serializer] Add special '*' serialization group that allows any group
2 parents 704c648 + 54e24a8 commit efdc35c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ protected function getAllowedAttributes($classOrObject, array $context, bool $at
250250
// If you update this check, update accordingly the one in Symfony\Component\PropertyInfo\Extractor\SerializerExtractor::getProperties()
251251
if (
252252
!$ignore &&
253-
(false === $groups || array_intersect($attributeMetadata->getGroups(), $groups)) &&
253+
(false === $groups || array_intersect(array_merge($attributeMetadata->getGroups(), ['*']), $groups)) &&
254254
$this->isAllowedAttribute($classOrObject, $name = $attributeMetadata->getName(), null, $context)
255255
) {
256256
$allowedAttributes[] = $attributesAsString ? $name : $attributeMetadata;

src/Symfony/Component/Serializer/Tests/Normalizer/AbstractNormalizerTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public function testGetAllowedAttributesAsString()
7272

7373
$result = $this->normalizer->getAllowedAttributes('c', [AbstractNormalizer::GROUPS => ['other']], true);
7474
$this->assertEquals(['a3', 'a4'], $result);
75+
76+
$result = $this->normalizer->getAllowedAttributes('c', [AbstractNormalizer::GROUPS => ['*']], true);
77+
$this->assertEquals(['a1', 'a2', 'a3', 'a4'], $result);
7578
}
7679

7780
public function testGetAllowedAttributesAsObjects()
@@ -104,6 +107,9 @@ public function testGetAllowedAttributesAsObjects()
104107

105108
$result = $this->normalizer->getAllowedAttributes('c', [AbstractNormalizer::GROUPS => ['other']], false);
106109
$this->assertEquals([$a3, $a4], $result);
110+
111+
$result = $this->normalizer->getAllowedAttributes('c', [AbstractNormalizer::GROUPS => ['*']], false);
112+
$this->assertEquals([$a1, $a2, $a3, $a4], $result);
107113
}
108114

109115
public function testObjectWithStaticConstructor()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy