class TimestampNormalizer in Drupal 8
Same name and namespace in other branches
- 9 core/modules/serialization/src/Normalizer/TimestampNormalizer.php \Drupal\serialization\Normalizer\TimestampNormalizer
Converts values for the Timestamp data type to and from common formats.
@internal
Note that \Drupal\Core\TypedData\Plugin\DataType\Timestamp::getDateTime() explicitly sets a default timezone of UTC. This ensures the string representation generated by DateTimeNormalizer::normalize() is also in UTC.
Hierarchy
- class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, CacheableNormalizerInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
- class \Drupal\serialization\Normalizer\DateTimeNormalizer implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
- class \Drupal\serialization\Normalizer\TimestampNormalizer
- class \Drupal\serialization\Normalizer\DateTimeNormalizer implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
Expanded class hierarchy of TimestampNormalizer
1 file declares its use of TimestampNormalizer
- TimestampNormalizerTest.php in core/
modules/ serialization/ tests/ src/ Unit/ Normalizer/ TimestampNormalizerTest.php
1 string reference to 'TimestampNormalizer'
- serialization.services.yml in core/
modules/ serialization/ serialization.services.yml - core/modules/serialization/serialization.services.yml
1 service uses TimestampNormalizer
- serializer.normalizer.timestamp in core/
modules/ serialization/ serialization.services.yml - Drupal\serialization\Normalizer\TimestampNormalizer
File
- core/
modules/ serialization/ src/ Normalizer/ TimestampNormalizer.php, line 16
Namespace
Drupal\serialization\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}
*/
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. | ||
DateTimeNormalizer:: |
protected | property | The system's date configuration. | |
DateTimeNormalizer:: |
public | function | Normalizes an object into a set of arrays/scalars. | 1 |
DateTimeNormalizer:: |
public | function | Constructs a new DateTimeNormalizer instance. | |
NormalizerBase:: |
protected | property | List of formats which supports (de-)normalization. | 3 |
NormalizerBase:: |
protected | function | Adds cacheability if applicable. | |
NormalizerBase:: |
protected | function | Checks if the provided format is supported by this normalizer. | 2 |
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:: |