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;
116 public function writeError(
Error $error,
string $message): \DOMDocument
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,
156 bool $deleted =
false
158 $doc = new \DOMDocument();
159 $doc->appendChild($doc->createElement(
160 $deleted ?
'deleted_header' :
'header',
161 $identifier .
':' . $datestamp->format(
'Y-m-d')
169 public function writeRecord(
171 \DateTimeImmutable $datestamp,
172 \DOMDocument $metadata
174 $doc = new \DOMDocument();
175 $doc->appendChild($root = $doc->createElement(
'record'));
179 $identifier .
':' . $datestamp->format(
'Y-m-d')
182 $root->appendChild($doc->importNode($metadata->documentElement,
true));
186 public function writeDeletedRecord(
188 \DateTimeImmutable $datestamp
190 $doc = new \DOMDocument();
191 $doc->appendChild($root = $doc->createElement(
'deleted_record'));
195 $identifier .
':' . $datestamp->format(
'Y-m-d')
201 public function writeSet(
string $spec,
string $name): \DOMDocument
203 $doc = new \DOMDocument();
204 $doc->appendChild($doc->createElement(
'set', $spec .
':' . $name));
208 public function writeResumptionToken(
210 int $complete_list_size,
213 $doc = new \DOMDocument();
214 $doc->appendChild($doc->createElement(
216 $token .
',fullsize=' . $complete_list_size .
',cursor=' . $cursor
221 public function writeResponse(
223 \DOMDocument ...$contents
225 return $this->writeResponseOrErrorResponse(
232 public function writeErrorResponse(
234 \DOMDocument ...$errors
236 return $this->writeResponseOrErrorResponse(
243 protected function writeResponseOrErrorResponse(
246 \DOMDocument ...$contents
253 $doc = new \DOMDocument();
254 $doc->appendChild($root = $doc->createElement($root_name));
255 $root->appendChild($doc->createElement(
257 $request->
baseURL() .
':' . $request->
verb()->value .
':' . implode(
',', $args)
259 foreach ($contents as $content) {
260 $root->appendChild($doc->importNode($content->documentElement,
true));
269 string $repo_name =
'',
270 string $contact_mail =
''
274 protected string $prefix,
275 protected string $repo_name,
276 protected string $contact_mail
280 public function getOAIIdentifierPrefix(): string
282 return $this->prefix;
285 public function getOAIContactMail(): string
287 return $this->contact_mail;
290 public function getOAIRepositoryName(): string
292 return $this->repo_name;
302 ?
string $earliest_datestamp =
null,
303 int $record_count = 0,
304 string ...$identifiers
306 $earliest_datestamp = $this->getDate($earliest_datestamp ??
'@0');
308 foreach ($identifiers as $identifier) {
309 $records[$identifier] =
new class ($identifier) extends
NullRecord {
310 public function __construct(
protected string $identifier)
317 public function __construct(
protected string $identifier)
321 public function isDeleted():
bool
323 return substr($this->identifier, 0, 3) ===
'del';
326 public function datestamp(): \DateTimeImmutable
328 return new \DateTimeImmutable(
329 explode(
'+', $this->identifier)[1],
330 new \DateTimeZone(
'UTC')
334 public function identfifier():
string
336 return $this->identifier;
341 public function metadata(): \DOMDocument
343 $doc = new \DOMDocument();
344 $doc->appendChild($doc->createElement(
'md',
'md for ' . $this->identifier));
350 return new class ($earliest_datestamp, $record_count, $records) extends
NullRepository {
351 public array $exposed_parameters = [];
354 protected \DateTimeImmutable $earliest_datestamp,
355 protected int $record_count,
356 protected array $records
360 public function getEarliestDatestamp(): \DateTimeImmutable
362 return $this->earliest_datestamp;
365 public function doesRecordWithIdentifierExist(
string $identifier): bool
367 return in_array($identifier, array_keys($this->records));
370 public function getRecordByIdentifier(
string $identifier): ?RecordInterface
372 return $this->records[$identifier] ??
null;
375 public function getRecords(
376 ?\DateTimeImmutable $from =
null,
377 ?\DateTimeImmutable $until =
null,
381 $this->exposed_parameters[] = [
382 'from' => $from?->format(
'Y-m-d'),
383 'until' => $until?->format(
'Y-m-d'),
387 yield
from $this->records;
390 public function getRecordInfos(
391 ?\DateTimeImmutable $from =
null,
392 ?\DateTimeImmutable $until =
null,
396 $this->exposed_parameters[] = [
397 'from' => $from?->format(
'Y-m-d'),
398 'until' => $until?->format(
'Y-m-d'),
402 foreach ($this->records as $record) {
403 yield $record->infos();
407 public function getRecordCount(
408 ?\DateTimeImmutable $from =
null,
409 ?\DateTimeImmutable $until =
null
411 return $this->record_count;
417 bool $valid_token =
true,
422 protected bool $valid_token,
427 public function generateToken(
429 ?\DateTimeImmutable $from_date,
430 ?\DateTimeImmutable $until_date
432 return 'next_offset=' . $offset .
':' .
433 'from=' . $from_date?->format(
'Y-m-d') .
':' .
434 'until=' . $until_date?->format(
'Y-m-d');
437 public function isTokenValid(
string $token): bool
439 return $this->valid_token;
442 public function appendArgumentsFromTokenToRequest(
443 RequestInterface $request,
445 ): RequestInterface {
446 return $this->appended_request;
449 public function getOffsetFromToken(
string $token):
int
451 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