ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Wrapper.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\Refinery\Factory as Refinery;
28
29class Wrapper implements WrapperInterface
30{
33
34 public function __construct(
37 ) {
38 $this->http = $http;
39 $this->refinery = $refinery;
40 }
41
42 public function requestHasArgument(Argument $argument): bool
43 {
44 return $this->http->wrapper()->query()->has($argument->value) ||
45 $this->http->wrapper()->post()->has($argument->value);
46 }
47
48 public function retrieveArgumentFromRequest(Argument $argument): string
49 {
50 if ($this->http->wrapper()->query()->has($argument->value)) {
51 return $this->http->wrapper()->query()->retrieve(
52 $argument->value,
53 $this->refinery->kindlyTo()->string()
54 );
55 }
56 if ($this->http->wrapper()->post()->has($argument->value)) {
57 return $this->http->wrapper()->post()->retrieve(
58 $argument->value,
59 $this->refinery->kindlyTo()->string()
60 );
61 }
62 return '';
63 }
64
65 public function sendResponseAndClose(
66 int $status_code,
67 string $message = '',
68 ?\DOMDocument $body = null
69 ): void {
70 $response = $this->http->response()
71 ->withHeader(ResponseHeader::CONTENT_TYPE, 'text/xml')
72 ->withStatus($status_code, $message);
73
74 if (!is_null($body)) {
75 $response = $response->withBody(Streams::ofString($body->saveXML()));
76 }
77
78 $this->http->saveResponse($response);
79 $this->http->sendResponse();
80 $this->http->close();
81 }
82}
Builds data types.
Definition: Factory.php:36
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41
sendResponseAndClose(int $status_code, string $message='', ?\DOMDocument $body=null)
Definition: Wrapper.php:65
retrieveArgumentFromRequest(Argument $argument)
Definition: Wrapper.php:48
__construct(GlobalHttpState $http, Refinery $refinery)
Definition: Wrapper.php:34
Interface GlobalHttpState.
Interface ResponseHeader.
static http()
Fetches the global http state from ILIAS.
$message
Definition: xapiexit.php:31
$response
Definition: xapitoken.php:93