ILIAS  trunk Revision v11.0_alpha-1866-gfa368f7776e
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Wrapper.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 
29 class Wrapper implements WrapperInterface
30 {
32  protected Refinery $refinery;
33 
34  public function __construct(
35  GlobalHttpState $http,
36  Refinery $refinery
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 }
retrieveArgumentFromRequest(Argument $argument)
Definition: Wrapper.php:48
__construct(GlobalHttpState $http, Refinery $refinery)
Definition: Wrapper.php:34
$response
Definition: xapitoken.php:93
sendResponseAndClose(int $status_code, string $message='', ?\DOMDocument $body=null)
Definition: Wrapper.php:65
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static http()
Fetches the global http state from ILIAS.
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41
$message
Definition: xapiexit.php:31