class BooleanNormalizer

Same name and namespace in other branches
  1. 8.9.x core/modules/serialization/tests/modules/test_datatype_boolean_emoji_normalizer/src/Normalizer/BooleanNormalizer.php \Drupal\test_datatype_boolean_emoji_normalizer\Normalizer\BooleanNormalizer
  2. 10 core/modules/serialization/tests/modules/test_datatype_boolean_emoji_normalizer/src/Normalizer/BooleanNormalizer.php \Drupal\test_datatype_boolean_emoji_normalizer\Normalizer\BooleanNormalizer
  3. 11.x core/modules/serialization/tests/modules/test_datatype_boolean_emoji_normalizer/src/Normalizer/BooleanNormalizer.php \Drupal\test_datatype_boolean_emoji_normalizer\Normalizer\BooleanNormalizer

Normalizes boolean data weirdly: renders them as 👍 (TRUE) or 👎 (FALSE).

Hierarchy

  • class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, \Drupal\serialization\Normalizer\CacheableNormalizerInterface, \Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
    • class \Drupal\test_datatype_boolean_emoji_normalizer\Normalizer\BooleanNormalizer extends \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface

Expanded class hierarchy of BooleanNormalizer

1 string reference to 'BooleanNormalizer'
test_datatype_boolean_emoji_normalizer.services.yml in core/modules/serialization/tests/modules/test_datatype_boolean_emoji_normalizer/test_datatype_boolean_emoji_normalizer.services.yml
core/modules/serialization/tests/modules/test_datatype_boolean_emoji_normalizer/test_datatype_boolean_emoji_normalizer.services.yml
1 service uses BooleanNormalizer
serializer.normalizer.boolean.datatype.emoji in core/modules/serialization/tests/modules/test_datatype_boolean_emoji_normalizer/test_datatype_boolean_emoji_normalizer.services.yml
Drupal\test_datatype_boolean_emoji_normalizer\Normalizer\BooleanNormalizer

File

core/modules/serialization/tests/modules/test_datatype_boolean_emoji_normalizer/src/Normalizer/BooleanNormalizer.php, line 12

Namespace

Drupal\test_datatype_boolean_emoji_normalizer\Normalizer
View source
class BooleanNormalizer extends NormalizerBase implements DenormalizerInterface {
    
    /**
     * {@inheritdoc}
     */
    protected $supportedInterfaceOrClass = BooleanData::class;
    
    /**
     * {@inheritdoc}
     */
    public function normalize($object, $format = NULL, array $context = []) {
        return $object->getValue() ? '👍' : '👎';
    }
    
    /**
     * {@inheritdoc}
     */
    public function denormalize($data, $class, $format = NULL, array $context = []) {
        if (!in_array($data, [
            '👍',
            '👎',
        ], TRUE)) {
            throw new \UnexpectedValueException('Only 👍 and 👎 are acceptable values.');
        }
        return $data === '👍';
    }
    
    /**
     * {@inheritdoc}
     */
    public function hasCacheableSupportsMethod() : bool {
        return TRUE;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
BooleanNormalizer::$supportedInterfaceOrClass protected property The interface or class that this Normalizer supports. Overrides NormalizerBase::$supportedInterfaceOrClass
BooleanNormalizer::denormalize public function
BooleanNormalizer::hasCacheableSupportsMethod public function Overrides NormalizerBase::hasCacheableSupportsMethod
BooleanNormalizer::normalize public function
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

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