Copied!

Base class for a normalizer dealing with objects.

Abstract
Constants
public Symfony\Component\Serializer\Normalizer\AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES = 'allow_extra_attributes'
 

If ATTRIBUTES are specified, and the source has fields that are not part of that list, either ignore those attributes (true) or throw an ExtraAttributesException (false).

public Symfony\Component\Serializer\Normalizer\AbstractNormalizer::ATTRIBUTES = 'attributes'
 

Limit (de)normalize to the specified names.

For nested structures, this list needs to reflect the object tree.

public Symfony\Component\Serializer\Normalizer\AbstractNormalizer::CALLBACKS = 'callbacks'
 

Hashmap of field name => callable to (de)normalize this field.

The callable is called if the field is encountered with the arguments:

  • mixed $attributeValue value of this field
  • object|string $object the whole object being normalized or the object's class being denormalized
  • string $attributeName name of the attribute being (de)normalized
  • string $format the requested format
  • array $context the serialization context
public Symfony\Component\Serializer\Normalizer\AbstractNormalizer::CIRCULAR_REFERENCE_HANDLER = 'circular_reference_handler'
 

Handler to call when a circular reference has been detected.

If you specify no handler, a CircularReferenceException is thrown.

The method will be called with ($object, $format, $context) and its return value is returned as the result of the normalize call.

public Symfony\Component\Serializer\Normalizer\AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT = 'circular_reference_limit'
 

How many loops of circular reference to allow while normalizing.

The default value of 1 means that when we encounter the same object a second time, we consider that a circular reference.

You can raise this value for special cases, e.g. in combination with the max depth setting of the object normalizer.

public Symfony\Component\Serializer\Normalizer\DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS = 'collect_denormalization_errors'
public Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer::DEEP_OBJECT_TO_POPULATE = 'deep_object_to_populate'
 

Flag to tell the denormalizer to also populate existing objects on attributes of the main object.

Setting this to true is only useful if you also specify the root object in OBJECT_TO_POPULATE.

public Symfony\Component\Serializer\Normalizer\AbstractNormalizer::DEFAULT_CONSTRUCTOR_ARGUMENTS = 'default_constructor_arguments'
 

Hashmap of default values for constructor arguments.

The names need to match the parameter names in the constructor arguments.

public Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer::DEPTH_KEY_PATTERN = 'depth_%s::%s'
 

How to track the current depth in the context.

public Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer::DISABLE_TYPE_ENFORCEMENT = 'disable_type_enforcement'
 

While denormalizing, we can verify that types match.

You can disable this by setting this flag to true.

public Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer::ENABLE_MAX_DEPTH = 'enable_max_depth'
 

Set to true to respect the max depth metadata on fields.

public Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer::EXCLUDE_FROM_CACHE_KEY = 'exclude_from_cache_key'
 

Specify which context key are not relevant to determine which attributes of an object to (de)normalize.

public Symfony\Component\Serializer\Normalizer\AbstractNormalizer::GROUPS = 'groups'
 

Only (de)normalize attributes that are in the specified groups.

public Symfony\Component\Serializer\Normalizer\AbstractNormalizer::IGNORED_ATTRIBUTES = 'ignored_attributes'
 

Skip the specified attributes when normalizing an object tree.

This list is applied to each element of nested structures.

Note: The behaviour for nested structures is different from ATTRIBUTES for historical reason. Aligning the behaviour would be a BC break.

public Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer::MAX_DEPTH_HANDLER = 'max_depth_handler'
 

Callback to allow to set a value for an attribute when the max depth has been reached.

If no callback is given, the attribute is skipped. If a callable is given, its return value is used (even if null).

The arguments are:

  • mixed $attributeValue value of this field
  • object $object the whole object being normalized
  • string $attributeName name of the attribute being normalized
  • string $format the requested format
  • array $context the serialization context
public Symfony\Component\Serializer\Normalizer\AbstractNormalizer::OBJECT_TO_POPULATE = 'object_to_populate'
 

Instead of creating a new instance of an object, update the specified object.

If you have a nested structure, child objects will be overwritten with new instances unless you set DEEP_OBJECT_TO_POPULATE to true.

public Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS = 'preserve_empty_objects'
 

Flag to control whether an empty object should be kept as an object (in JSON: {}) or converted to a list (in JSON: []).

public Symfony\Component\Serializer\Normalizer\AbstractNormalizer::REQUIRE_ALL_PROPERTIES = 'require_all_properties'
 

Require all properties to be listed in the input instead of falling back to null for nullable ones.

public Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer::SKIP_NULL_VALUES = 'skip_null_values'
 

Flag to control whether fields with the value null should be output when normalizing or omitted.

public Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES = 'skip_uninitialized_values'
 

Flag to control whether uninitialized PHP>=7.4 typed class properties should be excluded when normalizing.

Methods
public __construct(?Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface $classMetadataFactory = NULL, ?Symfony\Component\Serializer\NameConverter\NameConverterInterface $nameConverter = NULL, ?Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface $propertyTypeExtractor = NULL, ?Symfony\Component\Serializer\Mapping\ClassDiscriminatorResolverInterface $classDiscriminatorResolver = NULL, ?callable $objectClassResolver = NULL, array $defaultContext = [])
public denormalize(?mixed $data, string $type, ?string $format = NULL, array $context = []) : ?mixed
public abstract Symfony\Component\Serializer\Normalizer\NormalizerInterface::getSupportedTypes(?string $format) : array
 

Returns the types potentially supported by this normalizer.

For each supported formats (if applicable), the supported types should be returned as keys, and each type should be mapped to a boolean indicating if the result of supportsNormalization() can be cached or not (a result cannot be cached when it depends on the context or on the data.) A null value means that the normalizer does not support the corresponding type.

Use type "object" to match any classes or interfaces, and type "*" to match any types.

    public normalize(?mixed $object, ?string $format = NULL, array $context = []) : ArrayObject|array|string|int|float|bool|?null
    public Symfony\Component\Serializer\Normalizer\AbstractNormalizer::setSerializer(Symfony\Component\Serializer\SerializerInterface $serializer) : void
    public supportsDenormalization(?mixed $data, string $type, ?string $format = NULL, array $context = []) : bool
    public supportsNormalization(?mixed $data, ?string $format = NULL, array $context = []) : bool
    Constants
    protected Symfony\Component\Serializer\Normalizer\AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT_COUNTERS = 'circular_reference_limit_counters'
     
    • internal
    Properties
    protected ?Symfony\Component\Serializer\Mapping\ClassDiscriminatorResolverInterface $classDiscriminatorResolver
    protected ?Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface Symfony\Component\Serializer\Normalizer\AbstractNormalizer::$classMetadataFactory
    protected array Symfony\Component\Serializer\Normalizer\AbstractNormalizer::$defaultContext = ['allow_extra_attributes' => true, 'circular_reference_handler' => NULL, 'circular_reference_limit' => 1, 'ignored_attributes' => []]
    protected ?Symfony\Component\Serializer\NameConverter\NameConverterInterface Symfony\Component\Serializer\Normalizer\AbstractNormalizer::$nameConverter
    protected ?Symfony\Component\Serializer\SerializerInterface Symfony\Component\Serializer\Normalizer\AbstractNormalizer::$serializer = NULL
    Methods
    protected final Symfony\Component\Serializer\Normalizer\AbstractNormalizer::applyCallbacks(?mixed $value, object|string $object, string $attribute, ?string $format, array $context) : ?mixed
    protected createChildContext(array $parentContext, string $attribute, ?string $format) : array
     

    Overwritten to update the cache key for the child.

    We must not mix up the attribute cache between parent and children.

    • internal
    protected denormalizeParameter(ReflectionClass $class, ReflectionParameter $parameter, string $parameterName, ?mixed $parameterData, array $context, ?string $format = NULL) : ?mixed
     
    • internal
    protected abstract extractAttributes(object $object, ?string $format = NULL, array $context = []) : array
     

    Extracts attributes to normalize from the class of the given object, format and context.

    • return string[]
    protected Symfony\Component\Serializer\Normalizer\AbstractNormalizer::extractObjectToPopulate(string $class, array $context, ?string $key = NULL) : ?object
     

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

    • param string $class The class the object should be
    • param string|null $key They in which to look for the object to populate. Keeps backwards compatibility with AbstractNormalizer.
    protected Symfony\Component\Serializer\Normalizer\AbstractNormalizer::getAllowedAttributes(object|string $classOrObject, array $context, bool $attributesAsString = false) : array|bool
     

    Gets attributes to normalize using groups.

    • param bool $attributesAsString If false, return an array of {@link AttributeMetadataInterface}
    • return string[]|\AttributeMetadataInterface[]|bool
    • throws \LogicException if the 'allow_extra_attributes' context variable is false and no class metadata factory is provided
    protected Symfony\Component\Serializer\Normalizer\AbstractNormalizer::getAttributeDenormalizationContext(string $class, string $attribute, array $context) : array
     

    Computes the denormalization context merged with current one. Metadata always wins over global context, as more specific.

    • internal
    protected Symfony\Component\Serializer\Normalizer\AbstractNormalizer::getAttributeMetadata(object|string $objectOrClass, string $attribute) : ?Symfony\Component\Serializer\Mapping\AttributeMetadataInterface
     
    • internal
    protected Symfony\Component\Serializer\Normalizer\AbstractNormalizer::getAttributeNormalizationContext(object $object, string $attribute, array $context) : array
     

    Computes the normalization context merged with current one. Metadata always wins over global context, as more specific.

    • internal
    protected getAttributes(object $object, ?string $format, array $context) : array
     

    Gets and caches attributes for the given object, format and context.

    • return string[]
    protected abstract getAttributeValue(object $object, string $attribute, ?string $format = NULL, array $context = []) : ?mixed
     

    Gets the attribute value.

    protected Symfony\Component\Serializer\Normalizer\AbstractNormalizer::getConstructor(array $data, string $class, array $context, ReflectionClass $reflectionClass, array|bool $allowedAttributes) : ?ReflectionMethod
     

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

    protected Symfony\Component\Serializer\Normalizer\AbstractNormalizer::getGroups(array $context) : array
    protected Symfony\Component\Serializer\Normalizer\AbstractNormalizer::handleCircularReference(object $object, ?string $format = NULL, array $context = []) : ?mixed
     

    Handles a circular reference.

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

    • final
    • throws \CircularReferenceException
    protected instantiateObject(array $data, string $class, array $context, ReflectionClass $reflectionClass, array|bool $allowedAttributes, ?string $format = NULL) : object
    protected Symfony\Component\Serializer\Normalizer\AbstractNormalizer::isAllowedAttribute(object|string $classOrObject, string $attribute, ?string $format = NULL, array $context = []) : bool
     

    Is this attribute allowed?

    protected Symfony\Component\Serializer\Normalizer\AbstractNormalizer::isCircularReference(object $object, array $context) : bool
     

    Detects if the configured circular reference limit is reached.

    • throws \CircularReferenceException
    protected Symfony\Component\Serializer\Normalizer\AbstractNormalizer::prepareForDenormalization(?mixed $data) : array
     

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

    protected abstract setAttributeValue(object $object, string $attribute, ?mixed $value, ?string $format = NULL, array $context = []) : void
    protected final Symfony\Component\Serializer\Normalizer\AbstractNormalizer::validateCallbackContext(array $context, string $contextType = '') : void
     

    Validate callbacks set in context.

    • param string $contextType Used to specify which context is invalid in exceptions
    • throws \InvalidArgumentException
    Properties
    private array $attributesCache = []
    private readonly Closure $objectClassResolver
    private ?Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface $propertyTypeExtractor
    private array $typesCache = []
    Methods
    private getCacheKey(?string $format, array $context) : string|bool
     

    Builds the cache key for the attributes cache.

    The key must be different for every option in the context that could change which attributes should be handled.

    private getMappedClass(array $data, string $class, array $context) : string
     
    • return class-string
    private getNestedAttributes(string $class) : array
     

    Returns all attributes with a SerializedPath attribute and the respective path.

    private getTypes(string $currentClass, string $attribute) : ?array
     
    • return \Type[]|null
    private isMaxDepthReached(array $attributesMetadata, string $class, string $attribute, array $context) : bool
     

    Is the max depth reached for the given attribute?

    • param \AttributeMetadataInterface[] $attributesMetadata
    private isUninitializedValueError(Error|Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException $e) : bool
     

    This error may occur when specific object normalizer implementation gets attribute value by accessing a public uninitialized property or by calling a method accessing such property.

    private removeNestedValue(array $path, array $data) : array
    private updateData(array $data, string $attribute, ?mixed $attributeValue, string $class, ?string $format, array $context, ?array $attributesMetadata, ?Symfony\Component\Serializer\Mapping\ClassMetadataInterface $classMetadata) : array
     

    Sets an attribute and apply the name converter if necessary.

    private validateAndDenormalize(array $types, string $currentClass, string $attribute, ?mixed $data, ?string $format, array $context) : ?mixed
     

    Validates the submitted data and denormalizes it.

    • param \Type[] $types
    • throws \NotNormalizableValueException
    • throws \ExtraAttributesException
    • throws \MissingConstructorArgumentsException
    • throws \LogicException
    © 2024 Bruce Wells
    Search Namespaces \ Classes
    Configuration