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
Interfaces, Classes, Traits and Enums
- 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.
Table of Contents
- $decoder : ChainDecoder
- $encoder : ChainEncoder
- $cachedNormalizers : mixed
- $denormalizerCache : mixed
- $normalizerCache : mixed
- __construct() : mixed
- decode() : mixed
- {@inheritdoc}
- denormalize() : mixed
- {@inheritdoc}
- deserialize() : object|array<string|int, mixed>
- Deserializes data into the given type.
- encode() : mixed
- {@inheritdoc}
- normalize() : mixed
- {@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.
Properties
$decoder
protected
ChainDecoder
$decoder
$encoder
protected
ChainEncoder
$encoder
$cachedNormalizers
private
mixed
$cachedNormalizers
$denormalizerCache
private
mixed
$denormalizerCache
= []
$normalizerCache
private
mixed
$normalizerCache
= []
Methods
__construct()
public
__construct([array<string|int, \Symfony\Component\Serializer\Normalizer\NormalizerInterface|\Symfony\Component\Serializer\Normalizer\DenormalizerInterface> $normalizers = [] ][, array<string|int, \Symfony\Component\Serializer\Encoder\EncoderInterface|\Symfony\Component\Serializer\Encoder\DecoderInterface> $encoders = [] ]) : mixed
Parameters
- $normalizers : array<string|int, \Symfony\Component\Serializer\Normalizer\NormalizerInterface|\Symfony\Component\Serializer\Normalizer\DenormalizerInterface> = []
- $encoders : array<string|int, \Symfony\Component\Serializer\Encoder\EncoderInterface|\Symfony\Component\Serializer\Encoder\DecoderInterface> = []
Return values
mixed —decode()
{@inheritdoc}
public
final decode(mixed $data, mixed $format[, array<string|int, mixed> $context = [] ]) : mixed
Parameters
- $data : mixed
- $format : mixed
- $context : array<string|int, mixed> = []
Return values
mixed —denormalize()
{@inheritdoc}
public
denormalize(mixed $data, mixed $type[, mixed $format = null ][, array<string|int, mixed> $context = [] ]) : mixed
Parameters
- $data : mixed
- $type : mixed
- $format : mixed = null
- $context : array<string|int, mixed> = []
Tags
Return values
mixed —deserialize()
Deserializes data into the given type.
public
final deserialize(mixed $data, mixed $type, mixed $format[, array<string|int, mixed> $context = [] ]) : object|array<string|int, mixed>
Parameters
- $data : mixed
- $type : mixed
- $format : mixed
- $context : array<string|int, mixed> = []
Return values
object|array<string|int, mixed> —encode()
{@inheritdoc}
public
final encode(mixed $data, mixed $format[, array<string|int, mixed> $context = [] ]) : mixed
Parameters
- $data : mixed
- $format : mixed
- $context : array<string|int, mixed> = []
Return values
mixed —normalize()
{@inheritdoc}
public
normalize(mixed $data[, mixed $format = null ][, array<string|int, mixed> $context = [] ]) : mixed
Parameters
- $data : mixed
- $format : mixed = null
- $context : array<string|int, mixed> = []
Return values
mixed —serialize()
Serializes data in the appropriate format.
public
final serialize(mixed $data, mixed $format[, array<string|int, mixed> $context = [] ]) : string
Parameters
- $data : mixed
-
Any data
- $format : mixed
-
Format name
- $context : array<string|int, mixed> = []
-
Options normalizers/encoders have access to
Return values
string —supportsDecoding()
Checks whether the deserializer can decode from given format.
public
supportsDecoding(mixed $format[, array<string|int, mixed> $context = [] ]) : bool
Parameters
- $format : mixed
-
Format name
- $context : array<string|int, mixed> = []
-
options that decoders have access to
Return values
bool —supportsDenormalization()
Checks whether the given class is supported for denormalization by this normalizer.
public
supportsDenormalization(mixed $data, mixed $type[, mixed $format = null ][, array<string|int, mixed> $context = [] ]) : bool
Parameters
- $data : mixed
-
Data to denormalize from
- $type : mixed
-
The class to which the data should be denormalized
- $format : mixed = null
-
The format being deserialized from
- $context : array<string|int, mixed> = []
-
options that denormalizers have access to
Return values
bool —supportsEncoding()
Checks whether the serializer can encode to given format.
public
supportsEncoding(mixed $format[, array<string|int, mixed> $context = [] ]) : bool
Parameters
- $format : mixed
-
Format name
- $context : array<string|int, mixed> = []
-
options that encoders have access to
Return values
bool —supportsNormalization()
Checks whether the given class is supported for normalization by this normalizer.
public
supportsNormalization(mixed $data[, mixed $format = null ][, array<string|int, mixed> $context = [] ]) : bool
Parameters
- $data : mixed
-
Data to normalize
- $format : mixed = null
-
The format being (de-)serialized from or into
- $context : array<string|int, mixed> = []
-
options that normalizers have access to
Return values
bool —getDenormalizer()
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|null —getNormalizer()
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