ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Handler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ILIAS\Data\URI;
24 
25 class Handler
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 }
$response
Definition: xapitoken.php:93
The OAI PMH interface does not use the usual internal services of the MetaData component, as it should be lightweight and decoupled from everything else as much as possible.
global $DIC
Definition: shib_login.php:22
$message
Definition: xapiexit.php:31