class TimestampNormalizer in JSON:API 8.2
Converts values for the Timestamp data type to and from common formats.
@internal JSON:API maintains no PHP API. The API is the HTTP API. This class may change at any time and could break any dependencies on it.
@todo Remove when JSON:API requires a version of Drupal core that includes https://www.drupal.org/project/drupal/issues/2926508.
Hierarchy
- class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, CacheableNormalizerInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
- class \Drupal\jsonapi\Normalizer\NormalizerBase
- class \Drupal\jsonapi\ForwardCompatibility\Normalizer\DateTimeNormalizer implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
- class \Drupal\jsonapi\ForwardCompatibility\Normalizer\TimestampNormalizer
- class \Drupal\jsonapi\ForwardCompatibility\Normalizer\DateTimeNormalizer implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
- class \Drupal\jsonapi\Normalizer\NormalizerBase
Expanded class hierarchy of TimestampNormalizer
See also
https://www.drupal.org/project/jsonapi/issues/3032787
\Drupal\serialization\Normalizer\TimestampNormalizer
1 string reference to 'TimestampNormalizer'
1 service uses TimestampNormalizer
File
- src/
ForwardCompatibility/ Normalizer/ TimestampNormalizer.php, line 20
Namespace
Drupal\jsonapi\ForwardCompatibility\NormalizerView source
class TimestampNormalizer extends DateTimeNormalizer {
/**
* {@inheritdoc}
*/
protected $allowedFormats = [
'UNIX timestamp' => 'U',
'ISO 8601' => \DateTime::ISO8601,
'RFC 3339' => \DateTime::RFC3339,
];
/**
* {@inheritdoc}
*/
protected $supportedInterfaceOrClass = Timestamp::class;
/**
* {@inheritdoc}
*/
public function normalize($datetime, $format = NULL, array $context = []) {
return DrupalDateTime::createFromTimestamp($datetime
->getValue())
->setTimezone($this
->getNormalizationTimezone())
->format(\DateTime::RFC3339);
}
/**
* {@inheritdoc}
*/
protected function getNormalizationTimezone() {
return new \DateTimeZone('UTC');
}
/**
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = NULL, array $context = []) {
$denormalized = parent::denormalize($data, $class, $format, $context);
return $denormalized
->getTimestamp();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableNormalizerInterface:: |
constant | Name of key for bubbling cacheability metadata via serialization context. | ||
NormalizerBase:: |
protected | property |
List of formats which supports (de-)normalization. Overrides NormalizerBase:: |
|
NormalizerBase:: |
protected | function | Adds cacheability if applicable. | |
NormalizerBase:: |
protected | function |
Checks if the provided format is supported by this normalizer. Overrides NormalizerBase:: |
|
NormalizerBase:: |
protected static | function | Rasterizes a value recursively. | |
NormalizerBase:: |
public | function | Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() | 1 |
NormalizerBase:: |
public | function | Checks whether the given class is supported for normalization by this normalizer. | 1 |
TimestampNormalizer:: |
protected | property |
Allowed datetime formats for the denormalizer. Overrides DateTimeNormalizer:: |
|
TimestampNormalizer:: |
protected | property |
The interface or class that this Normalizer supports. Overrides DateTimeNormalizer:: |
|
TimestampNormalizer:: |
public | function |
Denormalizes data back into an object of the given class. Overrides DateTimeNormalizer:: |
|
TimestampNormalizer:: |
protected | function |
Gets the timezone to be used during normalization. Overrides DateTimeNormalizer:: |
|
TimestampNormalizer:: |
public | function |
Normalizes an object into a set of arrays/scalars. Overrides DateTimeNormalizer:: |