ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
InMemorySubjectRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26
28{
30 public array $entries = [];
31
32 public int $remove_subject_calls = 0;
33
34 public int $remove_subjects_calls = 0;
35
36 public function hasFor(SubjectId $subject, StorageNamespace $namespace, string $key): bool
37 {
38 return isset($this->entries[$this->keyOf($subject)][$namespace->value()][$key]);
39 }
40
41 public function readFor(SubjectId $subject, StorageNamespace $namespace, string $key): ?string
42 {
43 return $this->entries[$this->keyOf($subject)][$namespace->value()][$key] ?? null;
44 }
45
46 public function readAllFor(SubjectId $subject, StorageNamespace $namespace): array
47 {
48 return $this->entries[$this->keyOf($subject)][$namespace->value()] ?? [];
49 }
50
51 public function writeFor(SubjectId $subject, StorageNamespace $namespace, string $key, string $value): void
52 {
53 $this->entries[$this->keyOf($subject)][$namespace->value()][$key] = $value;
54 }
55
56 public function removeFor(SubjectId $subject, StorageNamespace $namespace, string $key): void
57 {
58 unset($this->entries[$this->keyOf($subject)][$namespace->value()][$key]);
59 }
60
61 public function removeAllFor(SubjectId $subject, StorageNamespace $namespace): void
62 {
63 unset($this->entries[$this->keyOf($subject)][$namespace->value()]);
64 }
65
66 public function removeSubject(SubjectId $subject): void
67 {
68 $this->remove_subject_calls++;
69 unset($this->entries[$this->keyOf($subject)]);
70 }
71
72 public function removeSubjects(array $subjects): void
73 {
74 $this->remove_subjects_calls++;
75 if ($subjects === []) {
76 return;
77 }
78
79 foreach ($subjects as $subject) {
80 if (!$subject instanceof SubjectId) {
81 throw new \InvalidArgumentException('Expected a subject id.');
82 }
83 $this->removeSubject($subject);
84 }
85 }
86
87 private function keyOf(SubjectId $subject): string
88 {
89 return $subject->provider() . ':' . $subject->id();
90 }
91}
Isolates the keys of one consumer from every other consumer of a storage.
Identifies a subject within the provider that names it.
Definition: SubjectId.php:30
removeFor(SubjectId $subject, StorageNamespace $namespace, string $key)
hasFor(SubjectId $subject, StorageNamespace $namespace, string $key)
readFor(SubjectId $subject, StorageNamespace $namespace, string $key)
removeAllFor(SubjectId $subject, StorageNamespace $namespace)
removeSubject(SubjectId $subject)
Removes every entry of one subject, in every namespace.
writeFor(SubjectId $subject, StorageNamespace $namespace, string $key, string $value)
readAllFor(SubjectId $subject, StorageNamespace $namespace)
Every present entry of one subject in one namespace.
Subject-scoped operations on the same persistent table as {.