Issue #3254331 by paulocs, longwave: [Symfony 6] Add "array|string|int|float|bool|\ArrayObject|null" to all Normalizer classes that implement the method ::normalize()
parent
77bd32e38f
commit
00ad1d7572
|
@ -66,7 +66,7 @@ class ContentEntityNormalizer extends NormalizerBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($entity, $format = NULL, array $context = []) {
|
||||
public function normalize($entity, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
$context += [
|
||||
'account' => NULL,
|
||||
'included_fields' => NULL,
|
||||
|
|
|
@ -63,7 +63,7 @@ class EntityReferenceItemNormalizer extends FieldItemNormalizer implements UuidR
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($field_item, $format = NULL, array $context = []) {
|
||||
public function normalize($field_item, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
// If this is not a fieldable entity, let the parent implementation handle
|
||||
// it, only fieldable entities are supported as embedded resources.
|
||||
if (!$this->targetEntityIsFieldable($field_item)) {
|
||||
|
|
|
@ -24,7 +24,7 @@ class FieldItemNormalizer extends NormalizerBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($field_item, $format = NULL, array $context = []) {
|
||||
public function normalize($field_item, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
// The values are wrapped in an array, and then wrapped in another array
|
||||
// keyed by field name so that field items can be merged by the
|
||||
// FieldNormalizer. This is necessary for the EntityReferenceItemNormalizer
|
||||
|
|
|
@ -18,7 +18,7 @@ class FieldNormalizer extends SerializationFieldNormalizer {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($field_items, $format = NULL, array $context = []) {
|
||||
public function normalize($field_items, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
$normalized_field_items = [];
|
||||
|
||||
// Get the field definition.
|
||||
|
|
|
@ -20,7 +20,7 @@ class DataNormalizer extends NormalizerBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
assert($object instanceof Data);
|
||||
$cacheable_normalizations = array_map(function ($resource) use ($format, $context) {
|
||||
return $this->serializer->normalize($resource, $format, $context);
|
||||
|
|
|
@ -74,7 +74,7 @@ abstract class EntityDenormalizerBase extends NormalizerBase implements Denormal
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
throw new \LogicException('This method should never be called.');
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class EntityReferenceFieldNormalizer extends FieldNormalizer {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($field, $format = NULL, array $context = []) {
|
||||
public function normalize($field, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
assert($field instanceof EntityReferenceFieldItemListInterface);
|
||||
// Build the relationship object based on the Entity Reference and normalize
|
||||
// that object instead.
|
||||
|
|
|
@ -59,7 +59,7 @@ class FieldItemNormalizer extends NormalizerBase implements DenormalizerInterfac
|
|||
* cacheability in mind, and hence bubbles cacheability out of band. This must
|
||||
* catch it, and pass it to the value object that JSON:API uses.
|
||||
*/
|
||||
public function normalize($field_item, $format = NULL, array $context = []) {
|
||||
public function normalize($field_item, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
assert($field_item instanceof FieldItemInterface);
|
||||
/** @var \Drupal\Core\TypedData\TypedDataInterface $property */
|
||||
$values = [];
|
||||
|
|
|
@ -30,7 +30,7 @@ class FieldNormalizer extends NormalizerBase implements DenormalizerInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($field, $format = NULL, array $context = []) {
|
||||
public function normalize($field, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
/** @var \Drupal\Core\Field\FieldItemListInterface $field */
|
||||
$normalized_items = $this->normalizeFieldItems($field, $format, $context);
|
||||
assert($context['resource_object'] instanceof ResourceObject);
|
||||
|
|
|
@ -48,7 +48,7 @@ class HttpExceptionNormalizer extends NormalizerBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
$cacheability = new CacheableMetadata();
|
||||
$cacheability->addCacheableDependency($object);
|
||||
return new HttpExceptionNormalizerValue($cacheability, static::rasterizeValueRecursive($this->buildErrorObjects($object)));
|
||||
|
|
|
@ -172,7 +172,7 @@ class JsonApiDocumentTopLevelNormalizer extends NormalizerBase implements Denorm
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
assert($object instanceof JsonApiDocumentTopLevel);
|
||||
$data = $object->getData();
|
||||
$document['jsonapi'] = CacheableNormalization::permanent([
|
||||
|
|
|
@ -90,7 +90,7 @@ class LinkCollectionNormalizer extends NormalizerBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
assert($object instanceof LinkCollection);
|
||||
$normalized = [];
|
||||
/** @var \Drupal\jsonapi\JsonApiResource\Link $link */
|
||||
|
|
|
@ -20,7 +20,7 @@ class RelationshipNormalizer extends NormalizerBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
assert($object instanceof Relationship);
|
||||
return CacheableNormalization::aggregate([
|
||||
'data' => $this->serializer->normalize($object->getData(), $format, $context),
|
||||
|
|
|
@ -48,7 +48,7 @@ class ResourceIdentifierNormalizer extends NormalizerBase implements Denormalize
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
assert($object instanceof ResourceIdentifier);
|
||||
$normalization = [
|
||||
'type' => $object->getTypeName(),
|
||||
|
|
|
@ -54,7 +54,7 @@ class ResourceObjectNormalizer extends NormalizerBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
assert($object instanceof ResourceObject);
|
||||
// If the fields to use were specified, only output those field values.
|
||||
$context['resource_object'] = $object;
|
||||
|
|
|
@ -57,7 +57,7 @@ final class Serializer extends SymfonySerializer {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($data, $format = NULL, array $context = []) {
|
||||
public function normalize($data, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
if ($this->selfSupportsNormalization($data, $format, $context)) {
|
||||
return parent::normalize($data, $format, $context);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class StringNormalizer extends NormalizerBase implements DenormalizerInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
return str_replace('super', 'NOT', $object->getValue());
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ class TraversableObjectNormalizer extends NormalizerBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
return $object->property;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class StringNormalizer extends FieldItemNormalizer implements DenormalizerInterf
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
$data = parent::normalize($object, $format, $context);
|
||||
$data['value'] = str_replace('super', 'NOT', $data['value']);
|
||||
return $data;
|
||||
|
|
|
@ -25,7 +25,7 @@ class ComplexDataNormalizer extends NormalizerBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
$attributes = [];
|
||||
// $object will not always match $supportedInterfaceOrClass.
|
||||
// @see \Drupal\serialization\Normalizer\EntityNormalizer
|
||||
|
|
|
@ -17,7 +17,7 @@ class ConfigEntityNormalizer extends EntityNormalizer {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
return static::getDataWithoutInternals($object->toArray());
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ class ContentEntityNormalizer extends EntityNormalizer {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($entity, $format = NULL, array $context = []) {
|
||||
public function normalize($entity, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
$context += [
|
||||
'account' => NULL,
|
||||
];
|
||||
|
|
|
@ -37,7 +37,7 @@ class DateTimeIso8601Normalizer extends DateTimeNormalizer {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($datetime, $format = NULL, array $context = []) {
|
||||
public function normalize($datetime, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
assert($datetime instanceof DateTimeIso8601);
|
||||
$field_item = $datetime->getParent();
|
||||
// @todo Remove this in https://www.drupal.org/project/drupal/issues/2958416.
|
||||
|
|
|
@ -54,7 +54,7 @@ class DateTimeNormalizer extends NormalizerBase implements DenormalizerInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($datetime, $format = NULL, array $context = []) {
|
||||
public function normalize($datetime, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
assert($datetime instanceof DateTimeInterface);
|
||||
$drupal_date_time = $datetime->getDateTime();
|
||||
if ($drupal_date_time === NULL) {
|
||||
|
|
|
@ -40,7 +40,7 @@ class EntityReferenceFieldItemNormalizer extends FieldItemNormalizer {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($field_item, $format = NULL, array $context = []) {
|
||||
public function normalize($field_item, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
$values = parent::normalize($field_item, $format, $context);
|
||||
|
||||
$this->normalizeRootReferenceValue($values, $field_item);
|
||||
|
|
|
@ -23,7 +23,7 @@ class ListNormalizer extends NormalizerBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
$attributes = [];
|
||||
foreach ($object as $fieldItem) {
|
||||
$attributes[] = $this->serializer->normalize($fieldItem, $format, $context);
|
||||
|
|
|
@ -17,7 +17,7 @@ class MarkupNormalizer extends NormalizerBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
return (string) $object;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ class NullNormalizer extends NormalizerBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ class PrimitiveDataNormalizer extends NormalizerBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
// Add cacheability if applicable.
|
||||
$this->addCacheableDependency($context, $object);
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ class TimestampItemNormalizer extends FieldItemNormalizer {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
return parent::normalize($object, $format, $context) + [
|
||||
// 'format' is not a property on Timestamp objects. This is present to
|
||||
// assist consumers of this data.
|
||||
|
|
|
@ -17,7 +17,7 @@ class TypedDataNormalizer extends NormalizerBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
$this->addCacheableDependency($context, $object);
|
||||
$value = $object->getValue();
|
||||
// Support for stringable value objects: avoid numerous custom normalizers.
|
||||
|
|
|
@ -18,7 +18,7 @@ class TextItemSillyNormalizer extends FieldItemNormalizer {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
$data = parent::normalize($object, $format, $context);
|
||||
$data['value'] .= '::silly_suffix';
|
||||
return $data;
|
||||
|
|
|
@ -19,7 +19,7 @@ class BooleanNormalizer extends NormalizerBase implements DenormalizerInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
return $object->getValue() ? '👍' : '👎';
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class BooleanItemNormalizer extends FieldItemNormalizer implements DenormalizerI
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
$data = parent::normalize($object, $format, $context);
|
||||
$data['value'] = $data['value'] ? '👍' : '👎';
|
||||
return $data;
|
||||
|
|
|
@ -14,21 +14,9 @@ class SerializationTestNormalizer implements NormalizerInterface {
|
|||
protected static $format = 'serialization_test';
|
||||
|
||||
/**
|
||||
* Normalizes an object into a set of arrays/scalars.
|
||||
*
|
||||
* @param object $object
|
||||
* Object to normalize.
|
||||
* @param string|null $format
|
||||
* (optional) Format the normalization result will be encoded as. Defaults
|
||||
* to NULL
|
||||
* @param array $context
|
||||
* (optional) The context data. Defaults to an empty array.
|
||||
*
|
||||
* @return array
|
||||
* An array containing a normalized representation of $object, appropriate
|
||||
* for encoding to the requested format.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []) {
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
$normalized = (array) $object;
|
||||
// Add identifying value that can be used to verify that the expected
|
||||
// normalizer was invoked.
|
||||
|
|
Loading…
Reference in New Issue