class ResourceObjectNormalizer extends NormalizerBase (View source)

internal  JSON:API maintains no PHP API since its API is the HTTP API. This class may change at any time and this will break any dependencies on it.
 

Converts the JSON:API module ResourceObject into a JSON:API array structure.

Traits

SerializerAwareTrait

Properties

protected $supportedInterfaceOrClass {@inheritdoc}
protected $format {@inheritdoc} from  NormalizerBase
protected ResourceObjectNormalizationCacher $cacher

The entity normalization cacher.

Methods

supportsNormalization($data, $format = NULL)

{@inheritdoc}

supportsDenormalization($data, $type, $format = NULL)

Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization()

bool
checkFormat(string $format = NULL)

Checks if the provided format is supported by this normalizer.

addCacheableDependency(array $context, $data)

Adds cacheability if applicable.

bool
hasCacheableSupportsMethod()

{@inheritdoc}

static mixed
rasterizeValueRecursive(mixed $value)

Rasterizes a value recursively.

__construct(ResourceObjectNormalizationCacher $cacher)

Constructs a ResourceObjectNormalizer object.

normalize($object, $format = NULL, array $context = [])

{@inheritdoc}

array
getNormalization(array $field_names, ResourceObject $object, string $format = NULL, array $context = [])

Normalizes an entity using the given fieldset.

static array
buildEmptyNormalization(ResourceObject $object)

Builds the empty normalization structure for cache misses.

serializeField(mixed $field, array $context, string $format)

Serializes a given field.

Details

supportsNormalization($data, $format = NULL)

{@inheritdoc}

Parameters

$data
$format

supportsDenormalization($data, $type, $format = NULL)

Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization()

This class doesn't implement DenormalizerInterface, but most of its child classes do. Therefore, this method is implemented at this level to reduce code duplication.

Parameters

$data
$type
$format

protected bool checkFormat(string $format = NULL)

Checks if the provided format is supported by this normalizer.

Parameters

string $format

The format to check.

Return Value

bool

TRUE if the format is supported, FALSE otherwise. If no format is specified this will return TRUE.

protected addCacheableDependency(array $context, $data)

Adds cacheability if applicable.

Parameters

array $context

Context options for the normalizer.

$data

The data that might have cacheability information.

bool hasCacheableSupportsMethod()

{@inheritdoc}

Return Value

bool

static protected mixed rasterizeValueRecursive(mixed $value)

Rasterizes a value recursively.

This is mainly for configuration entities where a field can be a tree of values to rasterize.

Parameters

mixed $value

Either a scalar, an array or a rasterizable object.

Return Value

mixed

The rasterized value.

__construct(ResourceObjectNormalizationCacher $cacher)

Constructs a ResourceObjectNormalizer object.

Parameters

ResourceObjectNormalizationCacher $cacher

The entity normalization cacher.

normalize($object, $format = NULL, array $context = [])

{@inheritdoc}

Parameters

$object
$format
array $context

protected array getNormalization(array $field_names, ResourceObject $object, string $format = NULL, array $context = [])

Normalizes an entity using the given fieldset.

Parameters

array $field_names

The field names to normalize (the sparse fieldset, if any).

ResourceObject $object

The resource object to partially normalize.

string $format

The format in which the normalization will be encoded.

array $context

Context options for the normalizer.

Return Value

array

An array with two key-value pairs:

  • 'base': array, the base normalization of the entity, that does not depend on which sparse fieldset was requested.
  • 'fields': CacheableNormalization for all requested fields.

See also

\Drupal\jsonapi\Normalizer\::normalize()

static protected array buildEmptyNormalization(ResourceObject $object)

Builds the empty normalization structure for cache misses.

Parameters

ResourceObject $object

The resource object being normalized.

Return Value

array

The normalization structure as defined in ::getNormalization().

See also

\Drupal\jsonapi\Normalizer\::getNormalization()

protected CacheableNormalization serializeField(mixed $field, array $context, string $format)

Serializes a given field.

Parameters

mixed $field

The field to serialize.

array $context

The normalization context.

string $format

The serialization format.

Return Value

CacheableNormalization

The normalized value.