From 4190bfaf4851f81b651896826f11a62649c99af8 Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Mon, 1 Jun 2020 13:01:33 +0200 Subject: [PATCH] [PropertyInfo] Support using the SerializerExtractor with no group check --- .../Component/PropertyInfo/Extractor/SerializerExtractor.php | 4 ++-- .../PropertyInfo/Tests/Extractor/SerializerExtractorTest.php | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/PropertyInfo/Extractor/SerializerExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/SerializerExtractor.php index eb892428231d6..32716734a65bc 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/SerializerExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/SerializerExtractor.php @@ -35,7 +35,7 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory) */ public function getProperties(string $class, array $context = []): ?array { - if (!isset($context['serializer_groups']) || !\is_array($context['serializer_groups'])) { + if (!\array_key_exists('serializer_groups', $context) || (null !== $context['serializer_groups'] && !\is_array($context['serializer_groups']))) { return null; } @@ -48,7 +48,7 @@ public function getProperties(string $class, array $context = []): ?array foreach ($serializerClassMetadata->getAttributesMetadata() as $serializerAttributeMetadata) { $ignored = method_exists($serializerClassMetadata, 'isIgnored') && $serializerAttributeMetadata->isIgnored(); - if (!$ignored && array_intersect($context['serializer_groups'], $serializerAttributeMetadata->getGroups())) { + if (!$ignored && (null === $context['serializer_groups'] || array_intersect($context['serializer_groups'], $serializerAttributeMetadata->getGroups()))) { $properties[] = $serializerAttributeMetadata->getName(); } } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/SerializerExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/SerializerExtractorTest.php index 4e5d3ff12cc59..22bee2e2782ba 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/SerializerExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/SerializerExtractorTest.php @@ -40,4 +40,9 @@ public function testGetProperties() $this->extractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', ['serializer_groups' => ['a']]) ); } + + public function testGetPropertiesWithAnyGroup() + { + $this->assertSame(['analyses', 'feet'], $this->extractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\AdderRemoverDummy', ['serializer_groups' => null])); + } } 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