ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
DenormalizingProcessor.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
28final class DenormalizingProcessor implements Processor
29{
30 public function __construct(
31 private readonly Registry $registry,
32 private readonly ?string $legacy_version
33 ) {
34 }
35
36 public function process(object $carry): void
37 {
38 if (!($carry instanceof DenormalizeCarry)) {
39 return;
40 }
41
42 if ($carry->normalized() === null) {
43 $carry->setResult(null);
44 return;
45 }
46
47 if (is_string($carry->expected())) {
48 $normalizer = $this->registry->forDenormalization(
49 $carry->expected(),
50 $this->legacy_version
51 );
52 if ($normalizer !== null) {
53 $carry->setResult(
54 $normalizer->denormalize($carry->normalized(), $carry->expected())
55 );
56 return;
57 }
58 }
59
60 if ($carry->expected() instanceof FromNormalized) {
61 if (!is_array($carry->normalized())) {
62 throw new NormalizingException(
63 'Expected normalized array, got ' . get_debug_type($carry->normalized())
64 );
65 }
66 $carry->setResult($carry->expected()->fromNormalized(
67 $carry->normalized(),
68 $carry->transformations()
69 ));
70 }
71 }
72}
Exception thrown when a value cannot be normalized or denormalized.
Carries normalized data, its expected type and eventual result through denormalization processors.
__construct(private readonly Registry $registry, private readonly ?string $legacy_version)