ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
DefaultResponseSenderStrategy.php
Go to the documentation of this file.
1<?php
2
4
6
16{
17
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 $sendStatus = fpassthru($resource);
52
53 //free up resources
54 fclose($resource);
55 }
56
57 //check if the body was successfully send to the client
58 if ($sendStatus === false) {
59 throw new ResponseSendingException("Could not send body content to client.");
60 }
61 }
62}
An exception for terminatinating execution or to throw for unit testing.
sendResponse(ResponseInterface $response)
Sends the rendered response to the client.
$key
Definition: croninfo.php:18
Representation of an outgoing, server-side response.
$response