| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Symfony package. |
| 5 |
* |
| 6 |
* (c) Fabien Potencier <fabien@symfony.com> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
namespace WindPressDeps\Symfony\Component\PropertyInfo\Extractor; |
| 12 |
|
| 13 |
use WindPressDeps\Symfony\Component\PropertyInfo\PropertyListExtractorInterface; |
| 14 |
use WindPressDeps\Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface; |
| 15 |
/** |
| 16 |
* Lists available properties using Symfony Serializer Component metadata. |
| 17 |
* |
| 18 |
* @author Kévin Dunglas <dunglas@gmail.com> |
| 19 |
* |
| 20 |
* @final |
| 21 |
*/ |
| 22 |
class SerializerExtractor implements PropertyListExtractorInterface |
| 23 |
{ |
| 24 |
private $classMetadataFactory; |
| 25 |
public function __construct(ClassMetadataFactoryInterface $classMetadataFactory) |
| 26 |
{ |
| 27 |
$this->classMetadataFactory = $classMetadataFactory; |
| 28 |
} |
| 29 |
/** |
| 30 |
* {@inheritdoc} |
| 31 |
*/ |
| 32 |
public function getProperties(string $class, array $context = []): ?array |
| 33 |
{ |
| 34 |
if (!\array_key_exists('serializer_groups', $context) || null !== $context['serializer_groups'] && !\is_array($context['serializer_groups'])) { |
| 35 |
return null; |
| 36 |
} |
| 37 |
if (!$this->classMetadataFactory->getMetadataFor($class)) { |
| 38 |
return null; |
| 39 |
} |
| 40 |
$properties = []; |
| 41 |
$serializerClassMetadata = $this->classMetadataFactory->getMetadataFor($class); |
| 42 |
foreach ($serializerClassMetadata->getAttributesMetadata() as $serializerAttributeMetadata) { |
| 43 |
$ignored = method_exists($serializerAttributeMetadata, 'isIgnored') && $serializerAttributeMetadata->isIgnored(); |
| 44 |
if (!$ignored && (null === $context['serializer_groups'] || array_intersect($context['serializer_groups'], $serializerAttributeMetadata->getGroups()))) { |
| 45 |
$properties[] = $serializerAttributeMetadata->getName(); |
| 46 |
} |
| 47 |
} |
| 48 |
return $properties; |
| 49 |
} |
| 50 |
} |
| 51 |
|