PropertyNormalizer
class PropertyNormalizer extends AbstractObjectNormalizer
Converts between objects and arrays by mapping properties.
The normalization process looks for all the object's properties (public and private). The result is a map from property names to property values. Property values are normalized through the serializer.
The denormalization first looks at the constructor of the given class to see if any of the parameters have the same name as one of the properties. The constructor is then called with all parameters or an exception is thrown if any required parameters were not present as properties. Then the denormalizer walks through the given map of property names to property values to see if a property with the corresponding name exists. If found, the property gets the value.
Traits
Constants
Properties
protected SerializerInterface | $serializer | from SerializerAwareTrait | |
protected | $defaultContext | from AbstractNormalizer | |
protected | $circularReferenceLimit | from AbstractNormalizer | |
protected callable|null | $circularReferenceHandler | from AbstractNormalizer | |
protected ClassMetadataFactoryInterface|null | $classMetadataFactory | from AbstractNormalizer | |
protected NameConverterInterface|null | $nameConverter | from AbstractNormalizer | |
protected | $callbacks | from AbstractNormalizer | |
protected | $ignoredAttributes | from AbstractNormalizer | |
protected | $camelizedAttributes | from AbstractNormalizer | |
protected ClassDiscriminatorResolverInterface|null | $classDiscriminatorResolver | from AbstractObjectNormalizer |
Methods
Extract the object_to_populate
field from the context if it exists
and is an instance of the provided $class.
Sets the {@link ClassMetadataFactoryInterface} to use.
Sets circular reference handler.
Sets ignored attributes for normalization and denormalization.
No description
Detects if the configured circular reference limit is reached.
Gets attributes to normalize using groups.
Is this attribute allowed?
Normalizes the given data to an array. It's particularly useful during the denormalization process.
Returns the method to use to construct an object. This method must be either the object constructor or static.
Instantiates an object using constructor parameters when needed.
No description
No description
Checks whether the given class is supported for normalization by this normalizer.
Normalizes an object into a set of arrays/scalars.
Gets and caches attributes for the given object, format and context.
Extracts attributes to normalize from the class of the given object, format and context.
Gets the attribute value.
Sets a handler function that will be called when the max depth is reached.
Checks whether the given class is supported for denormalization by this normalizer.
Denormalizes data back into an object of the given class.
Sets attribute value.
Details
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.
__construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null, PropertyTypeExtractorInterface $propertyTypeExtractor = null, ClassDiscriminatorResolverInterface $classDiscriminatorResolver = null, callable $objectClassResolver = null, array $defaultContext = array())
Sets the {@link ClassMetadataFactoryInterface} to use.
AbstractNormalizer
setCircularReferenceLimit(int $circularReferenceLimit)
deprecated
deprecated since Symfony 4.2
Sets circular reference limit.
AbstractNormalizer
setCircularReferenceHandler(callable $circularReferenceHandler)
deprecated
deprecated since Symfony 4.2
Sets circular reference handler.
AbstractNormalizer
setCallbacks(array $callbacks)
deprecated
deprecated since Symfony 4.2
Sets normalization callbacks.
AbstractNormalizer
setIgnoredAttributes(array $ignoredAttributes)
deprecated
deprecated since Symfony 4.2
Sets ignored attributes for normalization and denormalization.
protected bool
isCircularReference(object $object, array $context)
Detects if the configured circular reference limit is reached.
protected mixed
handleCircularReference($object)
Handles a circular reference.
If a circular reference handler is set, it will be called. Otherwise, a {@class CircularReferenceException} will be thrown.
protected string[]|AttributeMetadataInterface[]|bool
getAllowedAttributes(string|object $classOrObject, array $context, bool $attributesAsString = false)
Gets attributes to normalize using groups.
protected bool
isAllowedAttribute(object|string $classOrObject, string $attribute, string|null $format = null, array $context = array())
Is this attribute allowed?
protected array
prepareForDenormalization(object|array $data)
Normalizes the given data to an array. It's particularly useful during the denormalization process.
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.
protected object
instantiateObject(array $data, string $class, array $context, ReflectionClass $reflectionClass, array|bool $allowedAttributes, string $format = null)
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.
protected
denormalizeParameter(ReflectionClass $class, ReflectionParameter $parameter, $parameterName, $parameterData, array $context, $format = null)
bool
supportsNormalization(mixed $data, string $format = null)
Checks whether the given class is supported for normalization by this normalizer.
array|string|int|float|bool
normalize(mixed $object, string $format = null, array $context = array())
Normalizes an object into a set of arrays/scalars.
protected string[]
getAttributes(object $object, string|null $format = null, array $context)
Gets and caches attributes for the given object, format and context.
protected string[]
extractAttributes(object $object, string|null $format = null, array $context = array())
Extracts attributes to normalize from the class of the given object, format and context.
protected mixed
getAttributeValue(object $object, string $attribute, string|null $format = null, array $context = array())
Gets the attribute value.
void
setMaxDepthHandler(callable|null $handler)
deprecated
deprecated since Symfony 4.2
Sets a handler function that will be called when the max depth is reached.
bool
supportsDenormalization(mixed $data, string $type, string $format = null)
Checks whether the given class is supported for denormalization by this normalizer.