19declare(strict_types=1);
23use PHPUnit\Framework\TestCase;
42 protected function getDate(
string $string): \DateTimeImmutable
44 return new \DateTimeImmutable($string,
new \DateTimeZone(
'UTC'));
49 $url = $this->createMock(URI::class);
50 $url->method(
'__toString')->willReturn($string);
60 array $arguments_with_values,
61 bool $correct_arguments =
true
63 $base_url = $this->
getURI($base_url);
65 return new class ($base_url, $verb, $arguments_with_values, $correct_arguments) extends
NullRequest {
67 protected URI $base_url,
69 protected array $arguments_with_values,
70 protected bool $correct_values
74 public function baseURL():
URI
76 return $this->base_url;
79 public function verb():
Verb
84 public function argumentKeys(): \Generator
86 foreach ($this->arguments_with_values as $argument_key => $argument_value) {
87 if (!is_null($r = Argument::tryFrom($argument_key))) {
93 public function hasArgument(
Argument $argument):
bool
95 return in_array($argument->value, array_keys($this->arguments_with_values));
98 public function argumentValue(
Argument $argument):
string
100 return $this->arguments_with_values[$argument->value] ??
'';
103 public function hasCorrectArguments(
108 return $this->correct_values;
118 $doc = new \DOMDocument();
119 $doc->appendChild($doc->createElement(
'error',
$error->value));
123 public function writeIdentifyElements(
124 string $repository_name,
126 \DateTimeImmutable $earliest_datestamp,
127 string $first_admin_email,
128 string ...$further_admin_emails
133 $earliest_datestamp->format(
'Y-m-d'),
136 foreach ($els as $idx => $el) {
137 $doc = new \DOMDocument();
138 $doc->appendChild($doc->createElement(
'info', $el));
146 public function writeMetadataFormat(): \DOMDocument
148 $doc = new \DOMDocument();
149 $doc->appendChild($doc->createElement(
'md_format',
'some metadata'));
153 public function writeRecordHeader(
155 \DateTimeImmutable $datestamp
157 $doc = new \DOMDocument();
158 $doc->appendChild($doc->createElement(
160 $identifier .
':' . $datestamp->format(
'Y-m-d')
168 public function writeRecord(
170 \DateTimeImmutable $datestamp,
171 \DOMDocument $metadata
173 $doc = new \DOMDocument();
174 $doc->appendChild($root = $doc->createElement(
'record'));
178 $identifier .
':' . $datestamp->format(
'Y-m-d')
181 $root->appendChild($doc->importNode($metadata->documentElement,
true));
185 public function writeSet(
string $spec,
string $name): \DOMDocument
187 $doc = new \DOMDocument();
188 $doc->appendChild($doc->createElement(
'set', $spec .
':' . $name));
192 public function writeResumptionToken(
194 int $complete_list_size,
197 $doc = new \DOMDocument();
198 $doc->appendChild($doc->createElement(
200 $token .
',fullsize=' . $complete_list_size .
',cursor=' . $cursor
205 public function writeResponse(
207 \DOMDocument ...$contents
209 return $this->writeResponseOrErrorResponse(
216 public function writeErrorResponse(
218 \DOMDocument ...$errors
220 return $this->writeResponseOrErrorResponse(
227 protected function writeResponseOrErrorResponse(
230 \DOMDocument ...$contents
237 $doc = new \DOMDocument();
238 $doc->appendChild($root = $doc->createElement($root_name));
239 $root->appendChild($doc->createElement(
241 $request->
baseURL() .
':' . $request->
verb()->value .
':' . implode(
',', $args)
243 foreach ($contents as $content) {
244 $root->appendChild($doc->importNode($content->documentElement,
true));
253 string $repo_name =
'',
254 string $contact_mail =
''
258 protected string $prefix,
259 protected string $repo_name,
260 protected string $contact_mail
264 public function getOAIIdentifierPrefix(): string
266 return $this->prefix;
269 public function getOAIContactMail(): string
271 return $this->contact_mail;
274 public function getOAIRepositoryName(): string
276 return $this->repo_name;
285 ?
string $earliest_datestamp =
null,
286 int $record_count = 0,
287 string ...$identifiers
289 $earliest_datestamp = $this->getDate($earliest_datestamp ??
'@0');
291 foreach ($identifiers as $identifier) {
292 $records[$identifier] =
new class ($identifier) extends
NullRecord {
293 public function __construct(
protected string $identifier)
300 public function __construct(
protected string $identifier)
304 public function datestamp(): \DateTimeImmutable
306 return new \DateTimeImmutable(
307 explode(
'+', $this->identifier)[1],
308 new \DateTimeZone(
'UTC')
312 public function identfifier():
string
314 return $this->identifier;
319 public function metadata(): \DOMDocument
321 $doc = new \DOMDocument();
322 $doc->appendChild($doc->createElement(
'md',
'md for ' . $this->identifier));
328 return new class ($earliest_datestamp, $record_count, $records) extends
NullRepository {
329 public array $exposed_parameters = [];
332 protected \DateTimeImmutable $earliest_datestamp,
333 protected int $record_count,
334 protected array $records
338 public function getEarliestDatestamp(): \DateTimeImmutable
340 return $this->earliest_datestamp;
343 public function doesRecordWithIdentifierExist(
string $identifier): bool
345 return in_array($identifier, array_keys($this->records));
348 public function getRecordByIdentifier(
string $identifier): ?RecordInterface
350 return $this->records[$identifier] ??
null;
353 public function getRecords(
354 ?\DateTimeImmutable $from =
null,
355 ?\DateTimeImmutable $until =
null,
359 $this->exposed_parameters[] = [
360 'from' => $from?->format(
'Y-m-d'),
361 'until' => $until?->format(
'Y-m-d'),
365 yield
from $this->records;
368 public function getRecordInfos(
369 ?\DateTimeImmutable $from =
null,
370 ?\DateTimeImmutable $until =
null,
374 $this->exposed_parameters[] = [
375 'from' => $from?->format(
'Y-m-d'),
376 'until' => $until?->format(
'Y-m-d'),
380 foreach ($this->records as $record) {
381 yield $record->infos();
385 public function getRecordCount(
386 ?\DateTimeImmutable $from =
null,
387 ?\DateTimeImmutable $until =
null
389 return $this->record_count;
395 bool $valid_token =
true,
400 protected bool $valid_token,
405 public function generateToken(
407 ?\DateTimeImmutable $from_date,
408 ?\DateTimeImmutable $until_date
410 return 'next_offset=' . $offset .
':' .
411 'from=' . $from_date?->format(
'Y-m-d') .
':' .
412 'until=' . $until_date?->format(
'Y-m-d');
415 public function isTokenValid(
string $token): bool
417 return $this->valid_token;
420 public function appendArgumentsFromTokenToRequest(
421 RequestInterface $request,
423 ): RequestInterface {
424 return $this->appended_request;
427 public function getOffsetFromToken(
string $token):
int
429 return (
int) str_replace(
'next_offset=',
'', explode(
':',
$token)[0]);
The scope of this class is split ilias-conform URI's into components.
__construct()
Constructor setup ILIAS global object @access public.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc