class DateTimeZoneNormalizer
Normalizes a { @author Jérôme Desjardins <jewome62@gmail.com>
Hierarchy
- class \Symfony\Component\Serializer\Normalizer\DateTimeZoneNormalizer implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface, \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
Expanded class hierarchy of DateTimeZoneNormalizer
See also
\DateTimeZone} object to a timezone string.
File
-
vendor/
symfony/ serializer/ Normalizer/ DateTimeZoneNormalizer.php, line 22
Namespace
Symfony\Component\Serializer\NormalizerView source
final class DateTimeZoneNormalizer implements NormalizerInterface, DenormalizerInterface {
public function getSupportedTypes(?string $format) : array {
return [
\DateTimeZone::class => true,
];
}
/**
* @throws InvalidArgumentException
*/
public function normalize(mixed $object, ?string $format = null, array $context = []) : string {
if (!$object instanceof \DateTimeZone) {
throw new InvalidArgumentException('The object must be an instance of "\\DateTimeZone".');
}
return $object->getName();
}
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []) : bool {
return $data instanceof \DateTimeZone;
}
/**
* @throws NotNormalizableValueException
*/
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []) : \DateTimeZone {
if ('' === $data || null === $data) {
throw NotNormalizableValueException::createForUnexpectedDataType('The data is either an empty string or null, you should pass a string that can be parsed as a DateTimeZone.', $data, [
'string',
], $context['deserialization_path'] ?? null, true);
}
try {
return new \DateTimeZone($data);
} catch (\Exception $e) {
throw NotNormalizableValueException::createForUnexpectedDataType($e->getMessage(), $data, [
'string',
], $context['deserialization_path'] ?? null, true, $e->getCode(), $e);
}
}
public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []) : bool {
return \DateTimeZone::class === $type;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
DateTimeZoneNormalizer::denormalize | public | function | Overrides DenormalizerInterface::denormalize | |
DateTimeZoneNormalizer::getSupportedTypes | public | function | Returns the types potentially supported by this normalizer. | Overrides NormalizerInterface::getSupportedTypes |
DateTimeZoneNormalizer::normalize | public | function | Overrides NormalizerInterface::normalize | |
DateTimeZoneNormalizer::supportsDenormalization | public | function | Checks whether the given class is supported for denormalization by this normalizer. | Overrides DenormalizerInterface::supportsDenormalization |
DateTimeZoneNormalizer::supportsNormalization | public | function | Checks whether the given class is supported for normalization by this normalizer. | Overrides NormalizerInterface::supportsNormalization |
DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS | public | constant |