function Serializer::getDenormalizer
Returns a matching denormalizer.
Parameters
mixed $data Data to restore:
string $class The expected class to instantiate:
string|null $format Format name, present to give the option to normalizers to act differently based on formats:
array $context Options available to the denormalizer:
2 calls to Serializer::getDenormalizer()
- Serializer::denormalize in vendor/
symfony/ serializer/ Serializer.php - Serializer::supportsDenormalization in vendor/
symfony/ serializer/ Serializer.php - Checks whether the given class is supported for denormalization by this normalizer.
File
-
vendor/
symfony/ serializer/ Serializer.php, line 327
Class
- Serializer
- Serializer serializes and deserializes data.
Namespace
Symfony\Component\SerializerCode
private function getDenormalizer(mixed $data, string $class, ?string $format, array $context) : ?DenormalizerInterface {
if (!isset($this->denormalizerCache[$format][$class])) {
$this->denormalizerCache[$format][$class] = [];
$genericType = class_exists($class) || interface_exists($class, false) ? 'object' : '*';
foreach ($this->normalizers as $k => $normalizer) {
if (!$normalizer instanceof DenormalizerInterface) {
continue;
}
$supportedTypes = $normalizer->getSupportedTypes($format);
$doesClassRepresentCollection = str_ends_with($class, '[]');
foreach ($supportedTypes as $supportedType => $isCacheable) {
if (\in_array($supportedType, [
'*',
'object',
], true) || $class !== $supportedType && ('object' !== $genericType || !is_subclass_of($class, $supportedType)) && !($doesClassRepresentCollection && str_ends_with($supportedType, '[]') && is_subclass_of(strstr($class, '[]', true), strstr($supportedType, '[]', true)))) {
continue;
}
if (null === $isCacheable) {
unset($supportedTypes['*'], $supportedTypes['object']);
}
elseif ($this->denormalizerCache[$format][$class][$k] = $isCacheable && $normalizer->supportsDenormalization(null, $class, $format, $context)) {
break 2;
}
break;
}
if (null === ($isCacheable = $supportedTypes[\array_key_exists($genericType, $supportedTypes) ? $genericType : '*'] ?? null)) {
continue;
}
if ($this->denormalizerCache[$format][$class][$k] ??= $isCacheable && $normalizer->supportsDenormalization(null, $class, $format, $context)) {
break;
}
}
}
foreach ($this->denormalizerCache[$format][$class] as $k => $cached) {
$normalizer = $this->normalizers[$k];
if ($cached || $normalizer->supportsDenormalization($data, $class, $format, $context)) {
return $normalizer;
}
}
return null;
}