ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
IdMappingProcessor.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use Psr\Log\LoggerInterface;
27
28final class IdMappingProcessor implements Processor
29{
31 private array $unresolved = [];
32
33 public function __construct(
34 private readonly \ilImportMapping $mapping,
35 private readonly string $component,
36 private readonly LoggerInterface $log
37 ) {
38 }
39
40 public function process(object $carry): void
41 {
42 if (
43 !($carry instanceof DenormalizeCarry)
44 || $carry->expected() !== Id::class
45 || !$carry->hasResult()
46 ) {
47 return;
48 }
49
50 $envelope = $carry->result();
51 if (!($envelope instanceof Id)) {
52 throw new NormalizingException('Expected id envelope, got ' . get_debug_type($envelope));
53 }
54
55 $new_id = $this->mapping->getMapping(
56 $this->component,
57 $envelope->getObject(),
58 (string) $envelope->getId()
59 );
60 if ($new_id === null) {
61 $this->unresolved[] = $envelope;
62 $this->log->warning(
63 "Unresolved id {$envelope->getObject()}:{$envelope->getId()}"
64 );
65 return;
66 }
67
68 if (is_int($envelope->getId())) {
69 $new_id = (int) $new_id;
70 }
71
72 $carry->setResult(new Id($new_id, $envelope->getObject()));
73 $this->log->debug(
74 "Replaced id {$envelope->getObject()}:{$envelope->getId()} with {$new_id}"
75 );
76 }
77
79 public function unresolved(): array
80 {
81 return $this->unresolved;
82 }
83
84 public function mapping(): \ilImportMapping
85 {
86 return $this->mapping;
87 }
88}
Wrapper object for an object identifier and an optional object type the identifier belongs to.
Definition: Id.php:33
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 \ilImportMapping $mapping, private readonly string $component, private readonly LoggerInterface $log)
$log
Definition: ltiauth.php:50