Esempio n. 1
0
 /**
  * Sends the HTTP response back to a HTTP client.
  *
  * This calls php's header() function and streams the body to php://output.
  *
  * @param ResponseInterface $response
  * @return void
  */
 static function sendResponse(ResponseInterface $response)
 {
     header('HTTP/' . $response->getHttpVersion() . ' ' . $response->getStatus() . ' ' . $response->getStatusText());
     foreach ($response->getHeaders() as $key => $value) {
         foreach ($value as $k => $v) {
             if ($k === 0) {
                 header($key . ': ' . $v);
             } else {
                 header($key . ': ' . $v, false);
             }
         }
     }
     $body = $response->getBody();
     if (is_null($body)) {
         return;
     }
     $contentLength = $response->getHeader('Content-Length');
     if ($contentLength !== null) {
         $output = fopen('php://output', 'wb');
         if (is_resource($body) && get_resource_type($body) == 'stream') {
             stream_copy_to_stream($body, $output, $contentLength);
         } else {
             fwrite($output, $body, $contentLength);
         }
     } else {
         file_put_contents('php://output', $body);
     }
     if (is_resource($body)) {
         fclose($body);
     }
 }
Esempio n. 2
0
 /**
  * Sends the HTTP response back to a HTTP client.
  *
  * This calls php's header() function and streams the body to php://output.
  *
  * @param ResponseInterface $response
  * @return void
  */
 static function sendResponse(ResponseInterface $response)
 {
     header('HTTP/' . $response->getHttpVersion() . ' ' . $response->getStatus() . ' ' . $response->getStatusText());
     foreach ($response->getHeaders() as $key => $value) {
         header($key . ': ' . $value);
     }
     file_put_contents('php://output', $response->getBody());
 }
 /**
  * Constructor
  *
  * @param ResponseInterface $response
  */
 function __construct(ResponseInterface $response)
 {
     $this->response = $response;
     parent::__construct($response->getStatusText(), $response->getStatus());
 }