ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Handler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
26{
28 protected \ilLogger $logger;
29
30 protected readonly URI $base_url;
31
32 public function __construct()
33 {
34 global $DIC;
35
36 $this->logger = $DIC->logger()->meta();
37 $this->initiator = new Initiator($DIC);
38 $this->base_url = new URI(rtrim(ILIAS_HTTP_PATH, '/') . '/oai.php');
39 }
40
41 public function sendResponseToRequest(): void
42 {
43 if (!$this->initiator->settings()->isOAIPMHActive()) {
44 $this->initiator->httpWrapper()->sendResponseAndClose(404);
45 return;
46 }
47
48 set_error_handler(static function (int $errno, string $errstr, string $errfile, int $errline): never {
49 throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
50 });
51
52 try {
53 $response = $this->initiator->requestProcessor()->getResponseToRequest(
54 $this->initiator->requestParser()->parseFromHTTP($this->base_url)
55 );
56 } catch (\Throwable $e) {
57 $this->logError($e->getMessage());
58 $this->initiator->httpWrapper()->sendResponseAndClose(500, $e->getMessage());
59 return;
60 } finally {
61 restore_error_handler();
62 }
63
64 $this->initiator->httpWrapper()->sendResponseAndClose(200, '', $response);
65 }
66
67 protected function logError(string $message): void
68 {
69 $this->logger->error($message);
70 }
71}
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
The OAI PMH interface does not use the usual internal services of the MetaData component,...
global $DIC
Definition: shib_login.php:26
$message
Definition: xapiexit.php:31
$response
Definition: xapitoken.php:93