Serializer
in package
implements
SerializerInterface, ContextAwareNormalizerInterface, ContextAwareDenormalizerInterface, ContextAwareEncoderInterface, ContextAwareDecoderInterface
Serializer serializes and deserializes data.
objects are turned into arrays by normalizers. arrays are turned into various output formats by encoders.
$serializer->serialize($obj, 'xml')
$serializer->decode($data, 'xml')
$serializer->denormalize($data, 'Class', 'xml')
Tags
Table of Contents
Interfaces
- SerializerInterface
- ContextAwareNormalizerInterface
- Adds the support of an extra $context parameter for the supportsNormalization method.
- ContextAwareDenormalizerInterface
- Adds the support of an extra $context parameter for the supportsDenormalization method.
- ContextAwareEncoderInterface
- Adds the support of an extra $context parameter for the supportsEncoding method.
- ContextAwareDecoderInterface
- Adds the support of an extra $context parameter for the supportsDecoding method.
Constants
- EMPTY_ARRAY_AS_OBJECT = 'empty_array_as_object'
- Flag to control whether an empty array should be transformed to an object (in JSON: {}) or to a list (in JSON: []).
- SCALAR_TYPES = ['int' => true, 'bool' => true, 'float' => true, 'string' => true]
Properties
- $decoder : ChainDecoder
- $encoder : ChainEncoder
- $denormalizerCache : mixed
- $normalizerCache : mixed
- $normalizers : mixed
Methods
- __construct() : mixed
- decode() : mixed
- {@inheritdoc}
- denormalize() : mixed
- {@inheritdoc}
- deserialize() : mixed
- Deserializes data into the given type.
- encode() : string
- {@inheritdoc}
- normalize() : array<string|int, mixed>|string|int|float|bool|ArrayObject|null
- {@inheritdoc}
- serialize() : string
- Serializes data in the appropriate format.
- supportsDecoding() : bool
- Checks whether the deserializer can decode from given format.
- supportsDenormalization() : bool
- Checks whether the given class is supported for denormalization by this normalizer.
- supportsEncoding() : bool
- Checks whether the serializer can encode to given format.
- supportsNormalization() : bool
- Checks whether the given class is supported for normalization by this normalizer.
- getDenormalizer() : DenormalizerInterface|null
- Returns a matching denormalizer.
- getNormalizer() : NormalizerInterface|null
- Returns a matching normalizer.
Constants
EMPTY_ARRAY_AS_OBJECT
Flag to control whether an empty array should be transformed to an object (in JSON: {}) or to a list (in JSON: []).
public
mixed
EMPTY_ARRAY_AS_OBJECT
= 'empty_array_as_object'
SCALAR_TYPES
private
mixed
SCALAR_TYPES
= ['int' => true, 'bool' => true, 'float' => true, 'string' => true]
Properties
$decoder
protected
ChainDecoder
$decoder
$encoder
protected
ChainEncoder
$encoder
$denormalizerCache
private
mixed
$denormalizerCache
= []
$normalizerCache
private
mixed
$normalizerCache
= []
$normalizers
private
mixed
$normalizers
= []
Methods
__construct()
public
__construct([array<string|int, NormalizerInterface|DenormalizerInterface> $normalizers = [] ][, array<string|int, EncoderInterface|DecoderInterface> $encoders = [] ]) : mixed
Parameters
- $normalizers : array<string|int, NormalizerInterface|DenormalizerInterface> = []
- $encoders : array<string|int, EncoderInterface|DecoderInterface> = []
decode()
{@inheritdoc}
public
final decode(string $data, string $format[, array<string|int, mixed> $context = [] ]) : mixed
Parameters
- $data : string
- $format : string
- $context : array<string|int, mixed> = []
denormalize()
{@inheritdoc}
public
denormalize(mixed $data, string $type[, string $format = null ][, array<string|int, mixed> $context = [] ]) : mixed
Parameters
- $data : mixed
- $type : string
- $format : string = null
- $context : array<string|int, mixed> = []
Tags
deserialize()
Deserializes data into the given type.
public
final deserialize(mixed $data, string $type, string $format[, array<string|int, mixed> $context = [] ]) : mixed
Parameters
- $data : mixed
- $type : string
- $format : string
- $context : array<string|int, mixed> = []
encode()
{@inheritdoc}
public
final encode(mixed $data, string $format[, array<string|int, mixed> $context = [] ]) : string
Parameters
- $data : mixed
- $format : string
- $context : array<string|int, mixed> = []
Return values
stringnormalize()
{@inheritdoc}
public
normalize(mixed $data[, string $format = null ][, array<string|int, mixed> $context = [] ]) : array<string|int, mixed>|string|int|float|bool|ArrayObject|null
Parameters
- $data : mixed
- $format : string = null
- $context : array<string|int, mixed> = []
Return values
array<string|int, mixed>|string|int|float|bool|ArrayObject|nullserialize()
Serializes data in the appropriate format.
public
final serialize(mixed $data, string $format[, array<string|int, mixed> $context = [] ]) : string
Parameters
- $data : mixed
-
Any data
- $format : string
-
Format name
- $context : array<string|int, mixed> = []
-
Options normalizers/encoders have access to
Return values
stringsupportsDecoding()
Checks whether the deserializer can decode from given format.
public
supportsDecoding(string $format[, array<string|int, mixed> $context = [] ]) : bool
Parameters
- $format : string
-
Format name
- $context : array<string|int, mixed> = []
-
options that decoders have access to
Return values
boolsupportsDenormalization()
Checks whether the given class is supported for denormalization by this normalizer.
public
supportsDenormalization(mixed $data, string $type[, string $format = null ][, array<string|int, mixed> $context = [] ]) : 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
- $context : array<string|int, mixed> = []
-
options that denormalizers have access to
Return values
boolsupportsEncoding()
Checks whether the serializer can encode to given format.
public
supportsEncoding(string $format[, array<string|int, mixed> $context = [] ]) : bool
Parameters
- $format : string
-
Format name
- $context : array<string|int, mixed> = []
-
options that encoders have access to
Return values
boolsupportsNormalization()
Checks whether the given class is supported for normalization by this normalizer.
public
supportsNormalization(mixed $data[, string $format = null ][, array<string|int, mixed> $context = [] ]) : bool
Parameters
- $data : mixed
-
Data to normalize
- $format : string = null
-
The format being (de-)serialized from or into
- $context : array<string|int, mixed> = []
-
options that normalizers have access to
Return values
boolgetDenormalizer()
Returns a matching denormalizer.
private
getDenormalizer(mixed $data, string $class, string $format, array<string|int, mixed> $context) : DenormalizerInterface|null
Parameters
- $data : mixed
-
Data to restore
- $class : string
-
The expected class to instantiate
- $format : string
-
Format name, present to give the option to normalizers to act differently based on formats
- $context : array<string|int, mixed>
-
Options available to the denormalizer
Return values
DenormalizerInterface|nullgetNormalizer()
Returns a matching normalizer.
private
getNormalizer(mixed $data, string $format, array<string|int, mixed> $context) : NormalizerInterface|null
Parameters
- $data : mixed
-
Data to get the serializer for
- $format : string
-
Format name, present to give the option to normalizers to act differently based on formats
- $context : array<string|int, mixed>
-
Options available to the normalizer