[Serializer] Add special '*' serialization group that allows any group
This commit is contained in:
parent
704c648ba5
commit
54e24a8999
@ -250,7 +250,7 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
||||
// If you update this check, update accordingly the one in Symfony\Component\PropertyInfo\Extractor\SerializerExtractor::getProperties()
|
||||
if (
|
||||
!$ignore &&
|
||||
(false === $groups || array_intersect($attributeMetadata->getGroups(), $groups)) &&
|
||||
(false === $groups || array_intersect(array_merge($attributeMetadata->getGroups(), ['*']), $groups)) &&
|
||||
$this->isAllowedAttribute($classOrObject, $name = $attributeMetadata->getName(), null, $context)
|
||||
) {
|
||||
$allowedAttributes[] = $attributesAsString ? $name : $attributeMetadata;
|
||||
|
@ -72,6 +72,9 @@ class AbstractNormalizerTest extends TestCase
|
||||
|
||||
$result = $this->normalizer->getAllowedAttributes('c', [AbstractNormalizer::GROUPS => ['other']], true);
|
||||
$this->assertEquals(['a3', 'a4'], $result);
|
||||
|
||||
$result = $this->normalizer->getAllowedAttributes('c', [AbstractNormalizer::GROUPS => ['*']], true);
|
||||
$this->assertEquals(['a1', 'a2', 'a3', 'a4'], $result);
|
||||
}
|
||||
|
||||
public function testGetAllowedAttributesAsObjects()
|
||||
@ -104,6 +107,9 @@ class AbstractNormalizerTest extends TestCase
|
||||
|
||||
$result = $this->normalizer->getAllowedAttributes('c', [AbstractNormalizer::GROUPS => ['other']], false);
|
||||
$this->assertEquals([$a3, $a4], $result);
|
||||
|
||||
$result = $this->normalizer->getAllowedAttributes('c', [AbstractNormalizer::GROUPS => ['*']], false);
|
||||
$this->assertEquals([$a1, $a2, $a3, $a4], $result);
|
||||
}
|
||||
|
||||
public function testObjectWithStaticConstructor()
|
||||
|
Reference in New Issue
Block a user