ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
NormalizingProcessor.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26
27final class NormalizingProcessor implements Processor
28{
29 public function __construct(
30 private readonly Registry $registry
31 ) {
32 }
33
34 public function process(object $carry): void
35 {
36 if (!($carry instanceof NormalizeCarry)) {
37 return;
38 }
39
40 if ($carry->value() === null || is_scalar($carry->value())) {
41 $carry->setResult($carry->value());
42 return;
43 }
44
45 if ($carry->value() instanceof ToNormalized) {
46 $carry->setResult($carry->value()->toNormalized(
47 $carry->transformations(),
48 $carry->context()
49 ));
50 return;
51 }
52
53 $normalizer = $this->registry->forNormalization(get_class($carry->value()));
54 if ($normalizer !== null) {
55 $carry->setResult($normalizer->normalize($carry->value()));
56 }
57 }
58}
Carries a value, context and eventual result through normalization processors.