class LinkCollectionNormalizer 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.
 

Normalizes a LinkCollection object.

The JSON:API specification has the concept of a "links collection". A links collection is a JSON object where each member of the object is a "link object". Unfortunately, this means that it is not possible to have more than one link for a given key.

When normalizing more than one link in a LinkCollection with the same key, a unique and random string is appended to the link's key after a double dash (--) to differentiate the links. See this class's hashByHref() method for details.

This may change with a later version of the JSON:API specification.

Traits

SerializerAwareTrait

Constants

LINK_KEY

The normalizer $context key name for the key of an individual link.

LINK_CONTEXT

The normalizer $context key name for the context object of the link.

Properties

protected $supportedInterfaceOrClass {@inheritdoc}
protected $format {@inheritdoc} from  NormalizerBase
protected string $hashSalt

A random string to use when hashing links.

protected AccountInterface $currentUser

The current user making the request.

Methods

bool
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(AccountInterface $current_user = NULL)

LinkCollectionNormalizer constructor.

array|string|int|float|bool|ArrayObject|null
normalize($object, $format = NULL, array $context = [])

{@inheritdoc}

string
hashByHref(Link $link)

Hashes a link using its href and its target attributes, if any.

Details

bool supportsNormalization($data, $format = NULL)

{@inheritdoc}

Parameters

$data
$format

Return Value

bool

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(AccountInterface $current_user = NULL)

LinkCollectionNormalizer constructor.

Parameters

AccountInterface $current_user

The current user.

array|string|int|float|bool|ArrayObject|null normalize($object, $format = NULL, array $context = [])

{@inheritdoc}

Parameters

$object
$format
array $context

Return Value

array|string|int|float|bool|ArrayObject|null

protected string hashByHref(Link $link)

Hashes a link using its href and its target attributes, if any.

This method generates an unpredictable, but deterministic, 7 character alphanumeric hash for a given link.

The hash is unpredictable because a random hash salt will be used for every request. The hash is deterministic because, within a single request, links with the same href and target attributes (i.o.w. duplicates) will generate equivalent hash values.

Parameters

Link $link

A link to be hashed.

Return Value

string

A 7 character alphanumeric hash.