References AbstractItemNormalizer
Reference
C
Class

ApiPlatform\Serializer\AbstractItemNormalizer

Base item normalizer.

class ApiPlatform\Serializer\AbstractItemNormalizer extends Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer implements Symfony\Component\Serializer\Normalizer\NormalizerInterface, Symfony\Component\Serializer\Normalizer\DenormalizerInterface, Symfony\Component\Serializer\SerializerAwareInterface
{
    public __construct($propertyNameCollectionFactory, `<a href="/docs/main/references/Metadata/Property/Factory/PropertyMetadataFactoryInterface">ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface</a>` $propertyMetadataFactory, `<a href="/docs/main/references/Api/IriConverterInterface">ApiPlatform\Api\IriConverterInterface</a>`|`<a href="/docs/main/references/Api/IriConverterInterface">ApiPlatform\Metadata\IriConverterInterface</a>` $iriConverter, `<a href="/docs/main/references/Api/ResourceClassResolverInterface">ApiPlatform\Api\ResourceClassResolverInterface</a>`|`<a href="/docs/main/references/Api/ResourceClassResolverInterface">ApiPlatform\Metadata\ResourceClassResolverInterface</a>` $resourceClassResolver, null|Symfony\Component\PropertyAccess\PropertyAccessorInterface $propertyAccessor, null|Symfony\Component\Serializer\NameConverter\NameConverterInterface $nameConverter, null|Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface $classMetadataFactory, array $defaultContext, null|`<a href="/docs/main/references/Metadata/Resource/Factory/ResourceMetadataCollectionFactoryInterface">ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface</a>` $resourceMetadataCollectionFactory, null|`<a href="/docs/main/references/Metadata/ResourceAccessCheckerInterface">ApiPlatform\Metadata\ResourceAccessCheckerInterface</a>` $resourceAccessChecker, null|`<a href="/docs/main/references/Serializer/TagCollectorInterface">ApiPlatform\Serializer\TagCollectorInterface $tagCollector)
    public supportsNormalization($data, null|string $format, array $context): bool
    public getSupportedTypes(null|string $format): array
    public hasCacheableSupportsMethod(): bool
    public normalize($object, null|string $format, array $context): ArrayObject|array|string|int|float|bool
    public supportsDenormalization($data, string $type, null|string $format, array $context): bool
    public denormalize($data, string $class, null|string $format, array $context)
    protected instantiateObject(array $data, string $class, array $context, ReflectionClass $reflectionClass, array|bool $allowedAttributes, null|string $format): object
    protected getClassDiscriminatorResolvedClass(array $data, string $class, array $context): string
    protected createConstructorArgument($parameterData, string $key, ReflectionParameter $constructorParameter, array $context, null|string $format)
    protected extractAttributes($object, $format, array $context): array&lt;int, string&gt;
    protected getAllowedAttributes(object|string $classOrObject, array $context, bool $attributesAsString): array|bool
    protected isAllowedAttribute(object|string $classOrObject, string $attribute, null|string $format, array $context): bool
    protected canAccessAttribute(null|object $object, string $attribute, array $context): bool
    protected canAccessAttributePostDenormalize(null|object $object, null|object $previousObject, string $attribute, array $context): bool
    protected setAttributeValue(object $object, string $attribute, $value, null|string $format, array $context): null
    protected validateType(string $attribute, Symfony\Component\PropertyInfo\Type $type, $value, null|string $format, array $context): null
    protected denormalizeCollection(string $attribute, ApiPlatform\Metadata\ApiProperty $propertyMetadata, Symfony\Component\PropertyInfo\Type $type, string $className, $value, null|string $format, array $context): array
    protected denormalizeRelation(string $attributeName, ApiPlatform\Metadata\ApiProperty $propertyMetadata, string $className, $value, null|string $format, array $context): object
    protected getFactoryOptions(array $context): array
    protected getAttributeValue(object $object, string $attribute, null|string $format, array $context)
    protected normalizeCollectionOfRelations(ApiPlatform\Metadata\ApiProperty $propertyMetadata, iterable $attributeValue, string $resourceClass, null|string $format, array $context): array
    protected normalizeRelation(ApiPlatform\Metadata\ApiProperty $propertyMetadata, null|object $relatedObject, string $resourceClass, null|string $format, array $context): ArrayObject|array|string
    protected getAttributes(object $object, null|string $format, array $context): array&lt;int, string&gt;
    protected denormalizeParameter(ReflectionClass $class, ReflectionParameter $parameter, string $parameterName, $parameterData, array $context, null|string $format)
    protected createChildContext(array $parentContext, string $attribute, null|string $format): array
    protected isCircularReference(object $object, array $context): bool
    protected handleCircularReference(object $object, null|string $format, array $context)
    protected getGroups(array $context): array
    protected prepareForDenormalization($data): array
    protected getConstructor(array $data, string $class, array $context, ReflectionClass $reflectionClass, array|bool $allowedAttributes): ReflectionMethod
    protected validateCallbackContext(array $context, string $contextType): null
    protected applyCallbacks($value, object|string $object, string $attribute, null|string $format, array $context)
    protected getAttributeNormalizationContext(object $object, string $attribute, array $context): array
    protected getAttributeDenormalizationContext(string $class, string $attribute, array $context): array
    protected getAttributeMetadata(object|string $objectOrClass, string $attribute): Symfony\Component\Serializer\Mapping\AttributeMetadataInterface
    protected extractObjectToPopulate(string $class, array $context, null|string $key): object
    public setSerializer(Symfony\Component\Serializer\SerializerInterface $serializer): null
    public clone($data)
    protected getInputClass(array $context): string
    protected getOutputClass(array $context): string
    protected createOperationContext(array $context, null|string $resourceClass): array
}

Properties

propertyAccessor

Symfony\Component\PropertyAccess\PropertyAccessorInterface $propertyAccessor

localCache

array $localCache

localFactoryOptionsCache

array $localFactoryOptionsCache

resourceAccessChecker

propertyNameCollectionFactory

propertyMetadataFactory

iriConverter

resourceClassResolver

tagCollector

classDiscriminatorResolver

Symfony\Component\Serializer\Mapping\ClassDiscriminatorResolverInterface $classDiscriminatorResolver

defaultContext

array $defaultContext

classMetadataFactory

Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface $classMetadataFactory

nameConverter

Symfony\Component\Serializer\NameConverter\NameConverterInterface $nameConverter

serializer

Symfony\Component\Serializer\SerializerInterface $serializer

resourceMetadataCollectionFactory

Methods

__construct

public __construct($propertyNameCollectionFactory, `<a href="/docs/main/references/Metadata/Property/Factory/PropertyMetadataFactoryInterface">ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface</a>` $propertyMetadataFactory, `<a href="/docs/main/references/Api/IriConverterInterface">ApiPlatform\Api\IriConverterInterface</a>`|`<a href="/docs/main/references/Api/IriConverterInterface">ApiPlatform\Metadata\IriConverterInterface</a>` $iriConverter, `<a href="/docs/main/references/Api/ResourceClassResolverInterface">ApiPlatform\Api\ResourceClassResolverInterface</a>`|`<a href="/docs/main/references/Api/ResourceClassResolverInterface">ApiPlatform\Metadata\ResourceClassResolverInterface</a>` $resourceClassResolver, null|Symfony\Component\PropertyAccess\PropertyAccessorInterface $propertyAccessor, null|Symfony\Component\Serializer\NameConverter\NameConverterInterface $nameConverter, null|Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface $classMetadataFactory, array $defaultContext, null|`<a href="/docs/main/references/Metadata/Resource/Factory/ResourceMetadataCollectionFactoryInterface">ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface</a>` $resourceMetadataCollectionFactory, null|`<a href="/docs/main/references/Metadata/ResourceAccessCheckerInterface">ApiPlatform\Metadata\ResourceAccessCheckerInterface</a>` $resourceAccessChecker, null|`<a href="/docs/main/references/Serializer/TagCollectorInterface">ApiPlatform\Serializer\TagCollectorInterface $tagCollector)

Parameters

propertyNameCollectionFactory`ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface`
propertyMetadataFactory`ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface`
iriConverter`ApiPlatform\Api\IriConverterInterface`
`ApiPlatform\Metadata\IriConverterInterface`
resourceClassResolver`ApiPlatform\Api\ResourceClassResolverInterface`
`ApiPlatform\Metadata\ResourceClassResolverInterface`
propertyAccessorSymfony\Component\PropertyAccess\PropertyAccessorInterface
nameConverterSymfony\Component\Serializer\NameConverter\NameConverterInterface
classMetadataFactorySymfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface
defaultContextarray
resourceMetadataCollectionFactory`ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface`
resourceAccessChecker`ApiPlatform\Metadata\ResourceAccessCheckerInterface`
tagCollector`ApiPlatform\Serializer\TagCollectorInterface`

supportsNormalization

Checks whether the given class is supported for normalization by this normalizer.

public supportsNormalization($data, null|string $format, array $context): bool

Parameters

data
formatstring
contextarray

Returns

bool

getSupportedTypes

public getSupportedTypes(null|string $format): array

Parameters

formatstring

Returns

array

hasCacheableSupportsMethod

public hasCacheableSupportsMethod(): bool

Returns

bool

normalize

Normalizes an object into a set of arrays/scalars.

public normalize($object, null|string $format, array $context): ArrayObject|array|string|int|float|bool

Parameters

object
formatstring
contextarray

Returns

ArrayObject
array
string
int
float
bool

supportsDenormalization

Checks whether the given class is supported for denormalization by this normalizer.

public supportsDenormalization($data, string $type, null|string $format, array $context): bool

Parameters

data
typestring
formatstring
contextarray

Returns

bool

denormalize

Denormalizes data back into an object of the given class.

public denormalize($data, string $class, null|string $format, array $context)

Parameters

data
classstring
formatstring
contextarray

Returns

instantiateObject

Method copy-pasted from symfony/serializer. Remove it after symfony/serializer version update @see https://github.com/symfony/symfony/pull/28263.

protected instantiateObject(array $data, string $class, array $context, ReflectionClass $reflectionClass, array|bool $allowedAttributes, null|string $format): object

Parameters

dataarray
classstring
contextarray
reflectionClassReflectionClass
allowedAttributesarray
bool
formatstring

Returns

object

getClassDiscriminatorResolvedClass

protected getClassDiscriminatorResolvedClass(array $data, string $class, array $context): string

Parameters

dataarray
classstring
contextarray

Returns

string

createConstructorArgument

protected createConstructorArgument($parameterData, string $key, ReflectionParameter $constructorParameter, array $context, null|string $format)

Parameters

parameterData
keystring
constructorParameterReflectionParameter
contextarray
formatstring

Returns

extractAttributes

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

protected extractAttributes($object, $format, array $context): array&lt;int, string&gt;

Parameters

object
format
contextarray

Returns

array<int, string>

getAllowedAttributes

Gets attributes to normalize using groups.

protected getAllowedAttributes(object|string $classOrObject, array $context, bool $attributesAsString): array|bool

Parameters

classOrObjectobject
string
contextarray
attributesAsStringbool

Returns

array
bool

isAllowedAttribute

Is this attribute allowed?

protected isAllowedAttribute(object|string $classOrObject, string $attribute, null|string $format, array $context): bool

Parameters

classOrObjectobject
string
attributestring
formatstring
contextarray

Returns

bool

canAccessAttribute

Check if access to the attribute is granted.

protected canAccessAttribute(null|object $object, string $attribute, array $context): bool

Parameters

objectobject
attributestring
contextarray

Returns

bool

canAccessAttributePostDenormalize

Check if access to the attribute is granted.

protected canAccessAttributePostDenormalize(null|object $object, null|object $previousObject, string $attribute, array $context): bool

Parameters

objectobject
previousObjectobject
attributestring
contextarray

Returns

bool

setAttributeValue

protected setAttributeValue(object $object, string $attribute, $value, null|string $format, array $context): null

Parameters

objectobject
attributestring
value
formatstring
contextarray

Returns

null

validateType

Validates the type of the value. Allows using integers as floats for JSON formats.

protected validateType(string $attribute, Symfony\Component\PropertyInfo\Type $type, $value, null|string $format, array $context): null

Parameters

attributestring
typeSymfony\Component\PropertyInfo\Type
value
formatstring
contextarray

Returns

null

denormalizeCollection

Denormalizes a collection of objects.

protected denormalizeCollection(string $attribute, ApiPlatform\Metadata\ApiProperty $propertyMetadata, Symfony\Component\PropertyInfo\Type $type, string $className, $value, null|string $format, array $context): array

Parameters

attributestring
propertyMetadata`ApiPlatform\Metadata\ApiProperty`
typeSymfony\Component\PropertyInfo\Type
classNamestring
value
formatstring
contextarray

Returns

array

denormalizeRelation

Denormalizes a relation.

protected denormalizeRelation(string $attributeName, ApiPlatform\Metadata\ApiProperty $propertyMetadata, string $className, $value, null|string $format, array $context): object

Parameters

attributeNamestring
propertyMetadata`ApiPlatform\Metadata\ApiProperty`
classNamestring
value
formatstring
contextarray

Returns

object

getFactoryOptions

Gets the options for the property name collection / property metadata factories.

protected getFactoryOptions(array $context): array

Parameters

contextarray

Returns

array

getAttributeValue

Gets the attribute value.

protected getAttributeValue(object $object, string $attribute, null|string $format, array $context)

Parameters

objectobject
attributestring
formatstring
contextarray

Returns

normalizeCollectionOfRelations

Normalizes a collection of relations (to-many).

protected normalizeCollectionOfRelations(ApiPlatform\Metadata\ApiProperty $propertyMetadata, iterable $attributeValue, string $resourceClass, null|string $format, array $context): array

Parameters

propertyMetadata`ApiPlatform\Metadata\ApiProperty`
attributeValueiterable
resourceClassstring
formatstring
contextarray

Returns

array

normalizeRelation

Normalizes a relation.

protected normalizeRelation(ApiPlatform\Metadata\ApiProperty $propertyMetadata, null|object $relatedObject, string $resourceClass, null|string $format, array $context): ArrayObject|array|string

Parameters

propertyMetadata`ApiPlatform\Metadata\ApiProperty`
relatedObjectobject
resourceClassstring
formatstring
contextarray

Returns

ArrayObject
array
string

clone

public clone($data)

Parameters

data

Returns

getInputClass

protected getInputClass(array $context): string

Parameters

contextarray

Returns

string

getOutputClass

protected getOutputClass(array $context): string

Parameters

contextarray

Returns

string

createOperationContext

This context is created when working on a relation context or items of a collection. It cleans the previously given context as the operation changes.

protected createOperationContext(array $context, null|string $resourceClass): array

Parameters

contextarray
resourceClassstring

Returns

array

Made with love by

Les-Tilleuls.coop can help you design and develop your APIs and web projects, and train your teams in API Platform, Symfony, Next.js, Kubernetes and a wide range of other technologies.

Learn more

Copyright © 2023 Kévin Dunglas

Sponsored by Les-Tilleuls.coop