ILIAS  release_8 Revision v8.23
DefaultResponseSenderStrategy.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
7 /******************************************************************************
8  *
9  * This file is part of ILIAS, a powerful learning management system.
10  *
11  * ILIAS is licensed with the GPL-3.0, you should have received a copy
12  * of said license along with the source code.
13  *
14  * If this is not the case or you just want to try ILIAS, you'll find
15  * us at:
16  * https://www.ilias.de
17  * https://github.com/ILIAS-eLearning
18  *
19  *****************************************************************************/
29 {
37  public function sendResponse(ResponseInterface $response): void
38  {
39  //check if the request is already send
40  if (headers_sent()) {
41  throw new ResponseSendingException("Response was already sent.");
42  }
43 
44  //set status code
45  http_response_code($response->getStatusCode());
46 
47  //render all headers
48  foreach (array_keys($response->getHeaders()) as $key) {
49  // See Mantis #37385.
50  if (strtolower($key) === 'set-cookie') {
51  foreach ($response->getHeader($key) as $header) {
52  header("$key: " . $header, false);
53  }
54  } else {
55  header("$key: " . $response->getHeaderLine($key));
56  }
57  }
58 
59  //rewind body stream
60  $response->getBody()->rewind();
61 
62  //detach psr-7 stream from resource
63  $resource = $response->getBody()->detach();
64 
65  $sendStatus = false;
66 
67  if (is_resource($resource)) {
68  set_time_limit(0);
69  try {
70  ob_end_clean(); // see https://mantis.ilias.de/view.php?id=32046
71  } catch (\Throwable $t) {
72  }
73 
74  $sendStatus = fpassthru($resource);
75 
76  //free up resources
77  fclose($resource);
78  }
79 
80  //check if the body was successfully send to the client
81  if ($sendStatus === false) {
82  throw new ResponseSendingException("Could not send body content to client.");
83  }
84  }
85 }
string $key
Consumer key/client ID value.
Definition: System.php:193
sendResponse(ResponseInterface $response)
Sends the rendered response to the client.
$response