| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\PropertyInfo\Extractor; |
| 13 |
|
| 14 |
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface; |
| 15 |
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
> |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
class SerializerExtractor implements PropertyListExtractorInterface |
| 25 |
{ |
| 26 |
public function __construct( |
| 27 |
private readonly ClassMetadataFactoryInterface $classMetadataFactory, |
| 28 |
) { |
| 29 |
} |
| 30 |
|
| 31 |
public function getProperties(string $class, array $context = []): ?array |
| 32 |
{ |
| 33 |
if (!\array_key_exists('serializer_groups', $context) || (null !== $context['serializer_groups'] && !\is_array($context['serializer_groups']))) { |
| 34 |
return null; |
| 35 |
} |
| 36 |
|
| 37 |
if (!$this->classMetadataFactory->hasMetadataFor($class)) { |
| 38 |
return null; |
| 39 |
} |
| 40 |
|
| 41 |
$properties = []; |
| 42 |
$serializerClassMetadata = $this->classMetadataFactory->getMetadataFor($class); |
| 43 |
|
| 44 |
foreach ($serializerClassMetadata->getAttributesMetadata() as $serializerAttributeMetadata) { |
| 45 |
if (!$serializerAttributeMetadata->isIgnored() && (null === $context['serializer_groups'] || \in_array('*', $context['serializer_groups'], true) || array_intersect($serializerAttributeMetadata->getGroups(), $context['serializer_groups']))) { |
| 46 |
$properties[] = $serializerAttributeMetadata->getName(); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
return $properties; |
| 51 |
} |
| 52 |
} |