ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
EnvelopeNormalizer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
32{
33 public function __construct(
34 private readonly Transformations $tt,
35 ) {
36 }
37
38 #[\Override]
39 public function normalize($value): array|float|bool|int|string|null
40 {
41 if (!($value instanceof Envelope)) {
42 throw new NormalizingException('Invalid envelope value', $value);
43 }
44
45 return $value->unpack($this->tt);
46 }
47
48 #[\Override]
49 public function denormalize(array|float|bool|int|string|null $value, string $type): Envelope
50 {
51 if (!in_array(Envelope::class, class_implements($type))) {
52 throw new NormalizingException('Invalid envelope type', $type);
53 }
54
55 return $type::pack($value, $this->tt);
56 }
57}
denormalize(array|float|bool|int|string|null $value, string $type)
Converts a normalized form back into a value.
Exception thrown when a value cannot be normalized or denormalized.
Provides a set of transformations for normalizing and denormalizing values.
An envelope carries intermediate data between pipes before the final normalization step.
Definition: Envelope.php:29
A Normalizer is responsible for converting a value into a normalized form and back.
Definition: Normalizer.php:35