abstract class AbstractNormalizer extends SerializerAwareNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface

Normalizer implementation.

Traits

Constants

CIRCULAR_REFERENCE_LIMIT

OBJECT_TO_POPULATE

GROUPS

ATTRIBUTES

ALLOW_EXTRA_ATTRIBUTES

Properties

protected SerializerInterface $serializer from SerializerAwareTrait
protected int $circularReferenceLimit
protected callable $circularReferenceHandler
protected ClassMetadataFactoryInterface|null $classMetadataFactory
protected NameConverterInterface|null $nameConverter
protected array $callbacks
protected array $ignoredAttributes
protected array $camelizedAttributes

Methods

setSerializer(SerializerInterface $serializer)

Sets the serializer.

object|null
extractObjectToPopulate(string $class, array $context, string $key = null)

Extract the object_to_populate field from the context if it exists and is an instance of the provided $class.

__construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null)

Sets the {@link ClassMetadataFactoryInterface} to use.

setCircularReferenceLimit(int $circularReferenceLimit)

Set circular reference limit.

setCircularReferenceHandler(callable $circularReferenceHandler)

Set circular reference handler.

setCallbacks(array $callbacks)

Set normalization callbacks.

setIgnoredAttributes(array $ignoredAttributes)

Set ignored attributes for normalization and denormalization.

bool
isCircularReference(object $object, array $context)

Detects if the configured circular reference limit is reached.

mixed
handleCircularReference(object $object)

Handles a circular reference.

string[]|AttributeMetadataInterface[]|bool
getAllowedAttributes(string|object $classOrObject, array $context, bool $attributesAsString = false)

Gets attributes to normalize using groups.

bool
isAllowedAttribute(object|string $classOrObject, string $attribute, string|null $format = null, array $context = [])

Is this attribute allowed?

array
prepareForDenormalization(object|array $data)

Normalizes the given data to an array. It's particularly useful during the denormalization process.

getConstructor(array $data, string $class, array $context, ReflectionClass $reflectionClass, array|bool $allowedAttributes)

Returns the method to use to construct an object. This method must be either the object constructor or static.

object
instantiateObject(array $data, $class, array $context, ReflectionClass $reflectionClass, $allowedAttributes)

Instantiates an object using constructor parameters when needed.

denormalizeParameter(ReflectionClass $class, ReflectionParameter $parameter, $parameterName, $parameterData, array $context, $format = null)

No description

array
createChildContext(array $parentContext, string $attribute)

No description

Details

in SerializerAwareTrait at line 31
setSerializer(SerializerInterface $serializer)

Sets the serializer.

Parameters

SerializerInterface $serializer A SerializerInterface instance

in ObjectToPopulateTrait at line 27
protected object|null extractObjectToPopulate(string $class, array $context, string $key = null)

Extract the object_to_populate field from the context if it exists and is an instance of the provided $class.

Parameters

string $class The class the object should be
array $context The denormalization context
string $key They in which to look for the object to populate. Keeps backwards compatibility with AbstractNormalizer.

Return Value

object|null an object if things check out, null otherwise

at line 76
__construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null)

Sets the {@link ClassMetadataFactoryInterface} to use.

Parameters

ClassMetadataFactoryInterface $classMetadataFactory
NameConverterInterface $nameConverter

at line 89
AbstractNormalizer setCircularReferenceLimit(int $circularReferenceLimit)

Set circular reference limit.

Parameters

int $circularReferenceLimit Limit of iterations for the same object

Return Value

AbstractNormalizer

at line 103
AbstractNormalizer setCircularReferenceHandler(callable $circularReferenceHandler)

Set circular reference handler.

Parameters

callable $circularReferenceHandler

Return Value

AbstractNormalizer

at line 119
AbstractNormalizer setCallbacks(array $callbacks)

Set normalization callbacks.

Parameters

array $callbacks Help normalize the result

Return Value

AbstractNormalizer

Exceptions

InvalidArgumentException if a non-callable callback is set

at line 136
AbstractNormalizer setIgnoredAttributes(array $ignoredAttributes)

Set ignored attributes for normalization and denormalization.

Parameters

array $ignoredAttributes

Return Value

AbstractNormalizer

at line 153
protected bool isCircularReference(object $object, array $context)

Detects if the configured circular reference limit is reached.

Parameters

object $object
array $context

Return Value

bool

Exceptions

CircularReferenceException

at line 184
protected mixed handleCircularReference(object $object)

Handles a circular reference.

If a circular reference handler is set, it will be called. Otherwise, a {@class CircularReferenceException} will be thrown.

Parameters

object $object

Return Value

mixed

Exceptions

CircularReferenceException

at line 204
protected string[]|AttributeMetadataInterface[]|bool getAllowedAttributes(string|object $classOrObject, array $context, bool $attributesAsString = false)

Gets attributes to normalize using groups.

Parameters

string|object $classOrObject
array $context
bool $attributesAsString If false, return an array of {@link AttributeMetadataInterface}

Return Value

string[]|AttributeMetadataInterface[]|bool

Exceptions

LogicException if the 'allow_extra_attributes' context variable is false and no class metadata factory is provided

at line 246
protected bool isAllowedAttribute(object|string $classOrObject, string $attribute, string|null $format = null, array $context = [])

Is this attribute allowed?

Parameters

object|string $classOrObject
string $attribute
string|null $format
array $context

Return Value

bool

at line 272
protected array prepareForDenormalization(object|array $data)

Normalizes the given data to an array. It's particularly useful during the denormalization process.

Parameters

object|array $data

Return Value

array

at line 289
protected ReflectionMethod|null getConstructor(array $data, string $class, array $context, ReflectionClass $reflectionClass, array|bool $allowedAttributes)

Returns the method to use to construct an object. This method must be either the object constructor or static.

Parameters

array $data
string $class
array $context
ReflectionClass $reflectionClass
array|bool $allowedAttributes

Return Value

ReflectionMethod|null

at line 313
protected object instantiateObject(array $data, $class, array $context, ReflectionClass $reflectionClass, $allowedAttributes)

Instantiates an object using constructor parameters when needed.

This method also allows to denormalize data into an existing object if it is present in the context with the object_to_populate. This object is removed from the context before being returned to avoid side effects when recursively normalizing an object graph.

Parameters

array $data
$class
array $context
ReflectionClass $reflectionClass
$allowedAttributes

Return Value

object

Exceptions

RuntimeException

at line 385
protected denormalizeParameter(ReflectionClass $class, ReflectionParameter $parameter, $parameterName, $parameterData, array $context, $format = null)

Parameters

ReflectionClass $class
ReflectionParameter $parameter
$parameterName
$parameterData
array $context
$format

at line 411
protected array createChildContext(array $parentContext, string $attribute)

Parameters

array $parentContext
string $attribute

Return Value

array