You are here

class StringNormalizer in Drupal 9

Same name in this branch
  1. 9 core/modules/jsonapi/tests/modules/jsonapi_test_data_type/src/Normalizer/StringNormalizer.php \Drupal\jsonapi_test_data_type\Normalizer\StringNormalizer
  2. 9 core/modules/jsonapi/tests/modules/jsonapi_test_field_type/src/Normalizer/StringNormalizer.php \Drupal\jsonapi_test_field_type\Normalizer\StringNormalizer
Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/modules/jsonapi_test_data_type/src/Normalizer/StringNormalizer.php \Drupal\jsonapi_test_data_type\Normalizer\StringNormalizer

Normalizes string data weirdly: replaces 'super' with 'NOT' and vice versa.

Hierarchy

  • class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, CacheableNormalizerInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
    • class \Drupal\jsonapi_test_data_type\Normalizer\StringNormalizer implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface

Expanded class hierarchy of StringNormalizer

1 string reference to 'StringNormalizer'
jsonapi_test_data_type.services.yml in core/modules/jsonapi/tests/modules/jsonapi_test_data_type/jsonapi_test_data_type.services.yml
core/modules/jsonapi/tests/modules/jsonapi_test_data_type/jsonapi_test_data_type.services.yml
1 service uses StringNormalizer
serializer.normalizer.string.jsonapi_test_data_type in core/modules/jsonapi/tests/modules/jsonapi_test_data_type/jsonapi_test_data_type.services.yml
Drupal\jsonapi_test_data_type\Normalizer\StringNormalizer

File

core/modules/jsonapi/tests/modules/jsonapi_test_data_type/src/Normalizer/StringNormalizer.php, line 12

Namespace

Drupal\jsonapi_test_data_type\Normalizer
View source
class StringNormalizer extends NormalizerBase implements DenormalizerInterface {

  /**
   * {@inheritdoc}
   */
  protected $supportedInterfaceOrClass = StringData::class;

  /**
   * {@inheritdoc}
   */
  public function normalize($object, $format = NULL, array $context = []) {
    return str_replace('super', 'NOT', $object
      ->getValue());
  }

  /**
   * {@inheritdoc}
   */
  public function denormalize($data, $class, $format = NULL, array $context = []) {
    return str_replace('NOT', 'super', $data);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY constant Name of key for bubbling cacheability metadata via serialization context.
NormalizerBase::$format protected property List of formats which supports (de-)normalization. 3
NormalizerBase::addCacheableDependency protected function Adds cacheability if applicable.
NormalizerBase::checkFormat protected function Checks if the provided format is supported by this normalizer. 1
NormalizerBase::supportsDenormalization public function Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() 1
NormalizerBase::supportsNormalization public function 1
StringNormalizer::$supportedInterfaceOrClass protected property The interface or class that this Normalizer supports. Overrides NormalizerBase::$supportedInterfaceOrClass
StringNormalizer::denormalize public function
StringNormalizer::normalize public function