ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
Handler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use Throwable;
24use ErrorException;
26use ilLogger;
31
32class Handler implements HandlerInterface
33{
34 protected readonly URI $base_url;
35
36 public function __construct(
37 protected ilLogger $logger,
38 protected SettingsInterface $settings,
39 protected HTTPWrapper $http_wrapper,
40 protected RequestParser $request_parser,
41 protected RequestProcessor $request_processor
42 ) {
43 $this->base_url = new URI(rtrim(ILIAS_HTTP_PATH, '/') . '/oai.php');
44 }
45
46 public function sendResponseToRequest(): void
47 {
48 if (!$this->settings->isOAIPMHActive()) {
49 $this->http_wrapper->sendResponseAndClose(404);
50 return;
51 }
52
53 set_error_handler(static function (int $errno, string $errstr, string $errfile, int $errline): never {
54 throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
55 });
56
57 try {
58 $response = $this->request_processor->getResponseToRequest(
59 $this->request_parser->parseFromHTTP($this->base_url)
60 );
61 } catch (Throwable $e) {
62 $this->logError($e->getMessage());
63 $this->http_wrapper->sendResponseAndClose(500, $e->getMessage());
64 return;
65 } finally {
66 restore_error_handler();
67 }
68
69 $this->http_wrapper->sendResponseAndClose(200, '', $response);
70 }
71
72 protected function logError(string $message): void
73 {
74 $this->logger->error($message);
75 }
76}
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
__construct(protected ilLogger $logger, protected SettingsInterface $settings, protected HTTPWrapper $http_wrapper, protected RequestParser $request_parser, protected RequestProcessor $request_processor)
Definition: Handler.php:36
Component logger with individual log levels by component id.
Processes OAI PMH requests according to https://www.openarchives.org/OAI/openarchivesprotocol....
$response
Definition: xapitoken.php:90