82 lines
5.4 KiB
YAML
82 lines
5.4 KiB
YAML
|
name: MetadataAwareNameConverter
|
||
|
class_comment: null
|
||
|
dependencies:
|
||
|
- name: LogicException
|
||
|
type: class
|
||
|
source: Symfony\Component\Serializer\Exception\LogicException
|
||
|
- name: ClassMetadataFactoryInterface
|
||
|
type: class
|
||
|
source: Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface
|
||
|
- name: AbstractNormalizer
|
||
|
type: class
|
||
|
source: Symfony\Component\Serializer\Normalizer\AbstractNormalizer
|
||
|
properties: []
|
||
|
methods:
|
||
|
- name: getCacheValueForAttributesMetadata
|
||
|
visibility: private
|
||
|
parameters:
|
||
|
- name: class
|
||
|
- name: context
|
||
|
comment: "# * @author Fabien Bourigault <bourigaultfabien@gmail.com>\n# */\n# final\
|
||
|
\ class MetadataAwareNameConverter implements NameConverterInterface\n# {\n# /**\n\
|
||
|
# * @var array<string, array<string, string|null>>\n# */\n# private static array\
|
||
|
\ $normalizeCache = [];\n# \n# /**\n# * @var array<string, array<string, string|null>>\n\
|
||
|
# */\n# private static array $denormalizeCache = [];\n# \n# /**\n# * @var array<string,\
|
||
|
\ array<string, string>>\n# */\n# private static array $attributesMetadataCache\
|
||
|
\ = [];\n# \n# public function __construct(\n# private readonly ClassMetadataFactoryInterface\
|
||
|
\ $metadataFactory,\n# private readonly ?NameConverterInterface $fallbackNameConverter\
|
||
|
\ = null,\n# ) {\n# }\n# \n# public function normalize(string $propertyName, ?string\
|
||
|
\ $class = null, ?string $format = null, array $context = []): string\n# {\n#\
|
||
|
\ $class = 1 < \\func_num_args() ? func_get_arg(1) : null;\n# $format = 2 < \\\
|
||
|
func_num_args() ? func_get_arg(2) : null;\n# $context = 3 < \\func_num_args()\
|
||
|
\ ? func_get_arg(3) : [];\n# \n# if (null === $class) {\n# return $this->normalizeFallback($propertyName,\
|
||
|
\ $class, $format, $context);\n# }\n# \n# if (!\\array_key_exists($class, self::$normalizeCache)\
|
||
|
\ || !\\array_key_exists($propertyName, self::$normalizeCache[$class])) {\n# self::$normalizeCache[$class][$propertyName]\
|
||
|
\ = $this->getCacheValueForNormalization($propertyName, $class);\n# }\n# \n# return\
|
||
|
\ self::$normalizeCache[$class][$propertyName] ?? $this->normalizeFallback($propertyName,\
|
||
|
\ $class, $format, $context);\n# }\n# \n# public function denormalize(string $propertyName,\
|
||
|
\ ?string $class = null, ?string $format = null, array $context = []): string\n\
|
||
|
# {\n# $class = 1 < \\func_num_args() ? func_get_arg(1) : null;\n# $format = 2\
|
||
|
\ < \\func_num_args() ? func_get_arg(2) : null;\n# $context = 3 < \\func_num_args()\
|
||
|
\ ? func_get_arg(3) : [];\n# \n# if (null === $class) {\n# return $this->denormalizeFallback($propertyName,\
|
||
|
\ $class, $format, $context);\n# }\n# \n# $cacheKey = $this->getCacheKey($class,\
|
||
|
\ $context);\n# if (!\\array_key_exists($cacheKey, self::$denormalizeCache) ||\
|
||
|
\ !\\array_key_exists($propertyName, self::$denormalizeCache[$cacheKey])) {\n\
|
||
|
# self::$denormalizeCache[$cacheKey][$propertyName] = $this->getCacheValueForDenormalization($propertyName,\
|
||
|
\ $class, $context);\n# }\n# \n# return self::$denormalizeCache[$cacheKey][$propertyName]\
|
||
|
\ ?? $this->denormalizeFallback($propertyName, $class, $format, $context);\n#\
|
||
|
\ }\n# \n# private function getCacheValueForNormalization(string $propertyName,\
|
||
|
\ string $class): ?string\n# {\n# if (!$this->metadataFactory->hasMetadataFor($class))\
|
||
|
\ {\n# return null;\n# }\n# \n# $attributesMetadata = $this->metadataFactory->getMetadataFor($class)->getAttributesMetadata();\n\
|
||
|
# if (!\\array_key_exists($propertyName, $attributesMetadata)) {\n# return null;\n\
|
||
|
# }\n# \n# if (null !== $attributesMetadata[$propertyName]->getSerializedName()\
|
||
|
\ && null !== $attributesMetadata[$propertyName]->getSerializedPath()) {\n# throw\
|
||
|
\ new LogicException(\\sprintf('Found SerializedName and SerializedPath attributes\
|
||
|
\ on property \"%s\" of class \"%s\".', $propertyName, $class));\n# }\n# \n# return\
|
||
|
\ $attributesMetadata[$propertyName]->getSerializedName() ?? null;\n# }\n# \n\
|
||
|
# private function normalizeFallback(string $propertyName, ?string $class = null,\
|
||
|
\ ?string $format = null, array $context = []): string\n# {\n# return $this->fallbackNameConverter\
|
||
|
\ ? $this->fallbackNameConverter->normalize($propertyName, $class, $format, $context)\
|
||
|
\ : $propertyName;\n# }\n# \n# private function getCacheValueForDenormalization(string\
|
||
|
\ $propertyName, string $class, array $context): ?string\n# {\n# $cacheKey = $this->getCacheKey($class,\
|
||
|
\ $context);\n# if (!\\array_key_exists($cacheKey, self::$attributesMetadataCache))\
|
||
|
\ {\n# self::$attributesMetadataCache[$cacheKey] = $this->getCacheValueForAttributesMetadata($class,\
|
||
|
\ $context);\n# }\n# \n# return self::$attributesMetadataCache[$cacheKey][$propertyName]\
|
||
|
\ ?? null;\n# }\n# \n# private function denormalizeFallback(string $propertyName,\
|
||
|
\ ?string $class = null, ?string $format = null, array $context = []): string\n\
|
||
|
# {\n# return $this->fallbackNameConverter ? $this->fallbackNameConverter->denormalize($propertyName,\
|
||
|
\ $class, $format, $context) : $propertyName;\n# }\n# \n# /**\n# * @return array<string,\
|
||
|
\ string>"
|
||
|
- name: getCacheKey
|
||
|
visibility: private
|
||
|
parameters:
|
||
|
- name: class
|
||
|
- name: context
|
||
|
comment: null
|
||
|
traits:
|
||
|
- Symfony\Component\Serializer\Exception\LogicException
|
||
|
- Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface
|
||
|
- Symfony\Component\Serializer\Normalizer\AbstractNormalizer
|
||
|
interfaces:
|
||
|
- NameConverterInterface
|