ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 }
getStatusCode()
Gets the response status code.
getBody()
Gets the body of the message.
Representation of an outgoing, server-side response.
Add a drawing to the header
Definition: 04printing.php:69
sendResponse(ResponseInterface $response)
Sends the rendered response to the client.
$response
$key
Definition: croninfo.php:18
getHeaders()
Retrieves all message header values.
getHeaderLine($name)
Retrieves a comma-separated string of the values for a single header.