ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
DefaultResponseSenderStrategy.php
Go to the documentation of this file.
1<?php
2
4
5use Psr\Http\Message\ResponseInterface;
6
16{
17
26 public function sendResponse(ResponseInterface $response) : void
27 {
28 //check if the request is already send
29 if (headers_sent()) {
30 throw new ResponseSendingException("Response was already sent.");
31 }
32
33 //set status code
34 http_response_code($response->getStatusCode());
35
36 //render all headers
37 foreach ($response->getHeaders() as $key => $header) {
38 header("$key: " . $response->getHeaderLine($key));
39 }
40
41 //rewind body stream
42 $response->getBody()->rewind();
43
44 //detach psr-7 stream from resource
45 $resource = $response->getBody()->detach();
46
47 $sendStatus = false;
48
49 if (is_resource($resource)) {
50 set_time_limit(0);
51 ob_end_clean(); // see https://mantis.ilias.de/view.php?id=32046
52 $sendStatus = fpassthru($resource);
53
54 //free up resources
55 fclose($resource);
56 }
57
58 //check if the body was successfully send to the client
59 if ($sendStatus === false) {
60 throw new ResponseSendingException("Could not send body content to client.");
61 }
62 }
63}
An exception for terminatinating execution or to throw for unit testing.
sendResponse(ResponseInterface $response)
Sends the rendered response to the client.
$response