abstract class NormalizerBase in Drupal 10
Same name in this branch
- 10 core/modules/jsonapi/src/Normalizer/NormalizerBase.php \Drupal\jsonapi\Normalizer\NormalizerBase
- 10 core/modules/serialization/src/Normalizer/NormalizerBase.php \Drupal\serialization\Normalizer\NormalizerBase
Same name and namespace in other branches
- 8 core/modules/jsonapi/src/Normalizer/NormalizerBase.php \Drupal\jsonapi\Normalizer\NormalizerBase
- 9 core/modules/jsonapi/src/Normalizer/NormalizerBase.php \Drupal\jsonapi\Normalizer\NormalizerBase
Base normalizer used in all JSON:API normalizers.
@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.
Hierarchy
- class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, \Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface, CacheableNormalizerInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
- class \Drupal\jsonapi\Normalizer\NormalizerBase
Expanded class hierarchy of NormalizerBase
See also
https://www.drupal.org/project/drupal/issues/3032787
File
- core/
modules/ jsonapi/ src/ Normalizer/ NormalizerBase.php, line 17
Namespace
Drupal\jsonapi\NormalizerView source
abstract class NormalizerBase extends SerializationNormalizerBase {
/**
* {@inheritdoc}
*/
protected $format = 'api_json';
/**
* Rasterizes a value recursively.
*
* This is mainly for configuration entities where a field can be a tree of
* values to rasterize.
*
* @param mixed $value
* Either a scalar, an array or a rasterizable object.
*
* @return mixed
* The rasterized value.
*/
protected static function rasterizeValueRecursive($value) {
if (!$value || is_scalar($value)) {
return $value;
}
if (is_array($value)) {
$output = [];
foreach ($value as $key => $item) {
$output[$key] = static::rasterizeValueRecursive($item);
}
return $output;
}
if ($value instanceof CacheableNormalization) {
return $value
->getNormalization();
}
// If the object can be turned into a string it's better than nothing.
if (method_exists($value, '__toString')) {
return $value
->__toString();
}
// We give up, since we do not know how to rasterize this.
return NULL;
}
/**
* {@inheritdoc}
*/
protected function checkFormat($format = NULL) {
// The parent implementation allows format-specific normalizers to be used
// for formatless normalization. The JSON:API module wants to be cautious.
// Hence it only allows its normalizers to be used for the JSON:API format,
// to avoid JSON:API-specific normalizations showing up in the REST API.
return $format === $this->format;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableNormalizerInterface:: |
constant | Name of key for bubbling cacheability metadata via serialization context. | ||
NormalizerBase:: |
protected | property |
List of formats which supports (de-)normalization. Overrides NormalizerBase:: |
|
NormalizerBase:: |
protected | property | The interface or class that this Normalizer supports. | |
NormalizerBase:: |
protected | function | Adds cacheability if applicable. | |
NormalizerBase:: |
protected | function |
Checks if the provided format is supported by this normalizer. Overrides NormalizerBase:: |
|
NormalizerBase:: |
public | function | ||
NormalizerBase:: |
protected static | function | Rasterizes a value recursively. | |
NormalizerBase:: |
public | function | Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() | |
NormalizerBase:: |
public | function |