class BooleanNormalizer in Drupal 8
Same name and namespace in other branches
- 9 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, CacheableNormalizerInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
- class \Drupal\test_datatype_boolean_emoji_normalizer\Normalizer\BooleanNormalizer 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\NormalizerView 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 === '๐';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BooleanNormalizer:: |
protected | property |
The interface or class that this Normalizer supports. Overrides NormalizerBase:: |
|
BooleanNormalizer:: |
public | function | Denormalizes data back into an object of the given class. | |
BooleanNormalizer:: |
public | function | Normalizes an object into a set of arrays/scalars. | |
CacheableNormalizerInterface:: |
constant | Name of key for bubbling cacheability metadata via serialization context. | ||
NormalizerBase:: |
protected | property | List of formats which supports (de-)normalization. | 3 |
NormalizerBase:: |
protected | function | Adds cacheability if applicable. | |
NormalizerBase:: |
protected | function | Checks if the provided format is supported by this normalizer. | 2 |
NormalizerBase:: |
public | function | Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() | 1 |
NormalizerBase:: |
public | function | Checks whether the given class is supported for normalization by this normalizer. | 1 |