ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
CollectResources.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29use Psr\Log\LoggerInterface;
30
35{
39 private array $resources = [];
40
44 private array $import_mapping = [];
45
46 public function __construct(
47 private readonly IRSS $irss,
48 private readonly LoggerInterface $log
49 ) {
50 }
51
57 public function getResources(): array
58 {
59 return $this->resources;
60 }
61
66 public function storeMapping(string $old_id, ResourceIdentification $new_id): void
67 {
68 $this->import_mapping[$old_id] = $new_id;
69 }
70
71 public function process(object $carry): void
72 {
73 if ($carry instanceof NormalizeCarry && $carry->value() instanceof ResourceIdentification) {
74 $this->handleNormalization($carry->value());
75 }
76
77 if (
78 $carry instanceof DenormalizeCarry
79 && $carry->expected() === ResourceIdentification::class
80 && $carry->hasResult()
81 ) {
82 $carry->setResult($this->replaceRid($carry->result()));
83 }
84 }
85
86 private function handleNormalization(ResourceIdentification $rid): void
87 {
88 $this->resources[$rid->serialize()] = $this->irss->manage()->getResource($rid);
89 }
90
92 {
93 $id = $rid->serialize();
94 if (!isset($this->import_mapping[$id])) {
95 $this->log->warning("Unresolved resource id {$id}");
96 return $rid;
97 }
98
99 $this->log->debug("Replaced resource id {$id} with {$this->import_mapping[$id]->serialize()}");
100 return $this->import_mapping[$id];
101 }
102}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Collects resources during normalization and replaces mapped IDs during denormalization.
storeMapping(string $old_id, ResourceIdentification $new_id)
Store a mapping of an old resource id to a new resource id.
__construct(private readonly IRSS $irss, private readonly LoggerInterface $log)
Carries normalized data, its expected type and eventual result through denormalization processors.
Carries a value, context and eventual result through normalization processors.
$log
Definition: ltiauth.php:50