Same filename in this branch
- 10 core/modules/jsonapi/src/Normalizer/NormalizerBase.php
- 10 core/modules/serialization/src/Normalizer/NormalizerBase.php
Same filename and directory in other branches
- 8.9.x core/modules/serialization/src/Normalizer/NormalizerBase.php
- 9 core/modules/serialization/src/Normalizer/NormalizerBase.php
Namespace
Drupal\serialization\Normalizer
File
core/modules/serialization/src/Normalizer/NormalizerBase.php
View source
<?php
namespace Drupal\serialization\Normalizer;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Symfony\Component\Serializer\SerializerAwareInterface;
use Symfony\Component\Serializer\SerializerAwareTrait;
abstract class NormalizerBase implements SerializerAwareInterface, CacheableNormalizerInterface {
use SerializerAwareTrait;
protected $format;
public function supportsNormalization($data, string $format = NULL, array $context = []) : bool {
if (!is_object($data) || !$this
->checkFormat($format)) {
return FALSE;
}
if (property_exists($this, 'supportedInterfaceOrClass')) {
@trigger_error('Defining ' . static::class . '::supportedInterfaceOrClass property is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use getSupportedTypes() instead. See https://www.drupal.org/node/3359695', E_USER_DEPRECATED);
$supported = (array) $this->supportedInterfaceOrClass;
}
else {
$supported = array_keys($this
->getSupportedTypes($format));
}
return (bool) array_filter($supported, function ($name) use ($data) {
return $data instanceof $name;
});
}
public function supportsDenormalization($data, string $type, string $format = NULL, array $context = []) : bool {
if (!$this
->checkFormat($format)) {
return FALSE;
}
if (property_exists($this, 'supportedInterfaceOrClass')) {
@trigger_error('Defining ' . static::class . '::supportedInterfaceOrClass property is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use getSupportedTypes() instead. See https://www.drupal.org/node/3359695', E_USER_DEPRECATED);
$supported = (array) $this->supportedInterfaceOrClass;
}
else {
$supported = array_keys($this
->getSupportedTypes($format));
}
$subclass_check = function ($name) use ($type) {
return (class_exists($name) || interface_exists($name)) && is_subclass_of($type, $name, TRUE);
};
return in_array($type, $supported) || array_filter($supported, $subclass_check);
}
protected function checkFormat($format = NULL) {
if (!isset($format) || !isset($this->format)) {
return TRUE;
}
return in_array($format, (array) $this->format, TRUE);
}
protected function addCacheableDependency(array $context, $data) {
if ($data instanceof CacheableDependencyInterface && isset($context[static::SERIALIZATION_CONTEXT_CACHEABILITY])) {
$context[static::SERIALIZATION_CONTEXT_CACHEABILITY]
->addCacheableDependency($data);
}
}
public function hasCacheableSupportsMethod() : bool {
@trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use getSupportedTypes() instead. See https://www.drupal.org/node/3359695', E_USER_DEPRECATED);
return FALSE;
}
public function getSupportedTypes(?string $format) : array {
return [
'*' => FALSE,
];
}
}
Classes