class SerializationTestNormalizer

Same name in other branches
  1. 9 core/modules/serialization/tests/serialization_test/src/SerializationTestNormalizer.php \Drupal\serialization_test\SerializationTestNormalizer
  2. 10 core/modules/serialization/tests/serialization_test/src/SerializationTestNormalizer.php \Drupal\serialization_test\SerializationTestNormalizer
  3. 11.x core/modules/serialization/tests/serialization_test/src/SerializationTestNormalizer.php \Drupal\serialization_test\SerializationTestNormalizer

Hierarchy

Expanded class hierarchy of SerializationTestNormalizer

2 string references to 'SerializationTestNormalizer'
SerializationTestNormalizer::normalize in core/modules/serialization/tests/serialization_test/src/SerializationTestNormalizer.php
Normalizes an object into a set of arrays/scalars.
serialization_test.services.yml in core/modules/serialization/tests/serialization_test/serialization_test.services.yml
core/modules/serialization/tests/serialization_test/serialization_test.services.yml
1 service uses SerializationTestNormalizer
serializer.normalizer.serialization_test in core/modules/serialization/tests/serialization_test/serialization_test.services.yml
Drupal\serialization_test\SerializationTestNormalizer

File

core/modules/serialization/tests/serialization_test/src/SerializationTestNormalizer.php, line 7

Namespace

Drupal\serialization_test
View source
class SerializationTestNormalizer implements NormalizerInterface {
    
    /**
     * The format that this Normalizer supports.
     *
     * @var string
     */
    protected static $format = 'serialization_test';
    
    /**
     * Normalizes an object into a set of arrays/scalars.
     *
     * @param object $object
     *   Object to normalize.
     * @param string $format
     *   Format the normalization result will be encoded as.
     *
     * @return array
     *   An array containing a normalized representation of $object, appropriate
     *   for encoding to the requested format.
     */
    public function normalize($object, $format = NULL, array $context = []) {
        $normalized = (array) $object;
        // Add identifying value that can be used to verify that the expected
        // normalizer was invoked.
        $normalized['normalized_by'] = 'SerializationTestNormalizer';
        return $normalized;
    }
    
    /**
     * Checks whether format is supported by this normalizer.
     *
     * @param mixed $data
     *   Data to normalize.
     * @param string $format
     *   Format the normalization result will be encoded as.
     *
     * @return bool
     *   Returns TRUE if the normalizer can handle the request.
     */
    public function supportsNormalization($data, $format = NULL) {
        return static::$format === $format;
    }

}

Members

Title Sort descending Modifiers Object type Summary
SerializationTestNormalizer::$format protected static property The format that this Normalizer supports.
SerializationTestNormalizer::normalize public function Normalizes an object into a set of arrays/scalars.
SerializationTestNormalizer::supportsNormalization public function Checks whether format is supported by this normalizer.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.