Documentation

DateTimeNormalizer
in package
implements NormalizerInterface, DenormalizerInterface, CacheableSupportsMethodInterface

Normalizes an object implementing the {@see \DateTimeInterface} to a date string.

Denormalizes a date string to an instance of DateTime or DateTimeImmutable.

Tags
author

Kévin Dunglas dunglas@gmail.com

Table of Contents

Interfaces

NormalizerInterface
DenormalizerInterface
CacheableSupportsMethodInterface
Marker interface for normalizers and denormalizers that use only the type and the format in their supports*() methods.

Constants

FORMAT_KEY  = 'datetime_format'
TIMEZONE_KEY  = 'datetime_timezone'
SUPPORTED_TYPES  = [\DateTimeInterface::class => true, \DateTimeImmutable::class => true, \DateTime::class => true]

Properties

$defaultContext  : mixed

Methods

__construct()  : mixed
denormalize()  : mixed
Denormalizes data back into an object of the given class.
hasCacheableSupportsMethod()  : bool
normalize()  : array<string|int, mixed>|string|int|float|bool|ArrayObject|null
Normalizes an object into a set of arrays/scalars.
setDefaultContext()  : void
supportsDenormalization()  : bool
Checks whether the given class is supported for denormalization by this normalizer.
supportsNormalization()  : bool
Checks whether the given class is supported for normalization by this normalizer.
formatDateTimeErrors()  : array<string|int, string>
Formats datetime errors.
getTimezone()  : DateTimeZone|null

Constants

SUPPORTED_TYPES

private mixed SUPPORTED_TYPES = [\DateTimeInterface::class => true, \DateTimeImmutable::class => true, \DateTime::class => true]

Properties

$defaultContext

private mixed $defaultContext = [self::FORMAT_KEY => \DateTime::RFC3339, self::TIMEZONE_KEY => null]

Methods

__construct()

public __construct([array<string|int, mixed> $defaultContext = [] ]) : mixed
Parameters
$defaultContext : array<string|int, mixed> = []

denormalize()

Denormalizes data back into an object of the given class.

public denormalize(mixed $data, string $type[, string $format = null ][, array<string|int, mixed> $context = [] ]) : mixed
Parameters
$data : mixed

Data to restore

$type : string

The expected class to instantiate

$format : string = null

Format the given data was extracted from

$context : array<string|int, mixed> = []

Options available to the denormalizer

Tags
throws
NotNormalizableValueException

hasCacheableSupportsMethod()

public hasCacheableSupportsMethod() : bool
Return values
bool

normalize()

Normalizes an object into a set of arrays/scalars.

public normalize(mixed $object[, string $format = null ][, array<string|int, mixed> $context = [] ]) : array<string|int, mixed>|string|int|float|bool|ArrayObject|null
Parameters
$object : mixed

Object to normalize

$format : string = null

Format the normalization result will be encoded as

$context : array<string|int, mixed> = []

Context options for the normalizer

Tags
throws
InvalidArgumentException
Return values
array<string|int, mixed>|string|int|float|bool|ArrayObject|null

\ArrayObject is used to make sure an empty object is encoded as an object not an array

setDefaultContext()

public setDefaultContext(array<string|int, mixed> $defaultContext) : void
Parameters
$defaultContext : array<string|int, mixed>

supportsDenormalization()

Checks whether the given class is supported for denormalization by this normalizer.

public supportsDenormalization(mixed $data, string $type[, string $format = null ]) : bool
Parameters
$data : mixed

Data to denormalize from

$type : string

The class to which the data should be denormalized

$format : string = null

The format being deserialized from

Return values
bool

supportsNormalization()

Checks whether the given class is supported for normalization by this normalizer.

public supportsNormalization(mixed $data[, string $format = null ]) : bool
Parameters
$data : mixed

Data to normalize

$format : string = null

The format being (de-)serialized from or into

Return values
bool

formatDateTimeErrors()

Formats datetime errors.

private formatDateTimeErrors(array<string|int, mixed> $errors) : array<string|int, string>
Parameters
$errors : array<string|int, mixed>
Return values
array<string|int, string>

getTimezone()

private getTimezone(array<string|int, mixed> $context) : DateTimeZone|null
Parameters
$context : array<string|int, mixed>
Return values
DateTimeZone|null

        
On this page

Search results