Debian Codegraph @

lib/3rdParty/composer/symfony/property-info/Extractor/SerializerExtractor.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
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 * Lists available properties using Symfony Serializer Component metadata.
19 *
20 * @author Kévin Dunglas <[email protected]>
21 *
22 * @final
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 }