예제 #1
0
파일: Sapi.php 프로젝트: BlaBlaNet/hubzilla
 /**
  * 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);
     }
 }
예제 #2
0
 public function __construct(ResponseInterface &$response, $code = 0, $message = null, $previous = null)
 {
     if ($code === 0) {
         try {
             $status = $response->getStatus();
         } catch (\Exception $e) {
             throw new \LogicException(\get_class($this) . ' thrown with no status code and it was not set in the Response instance', 0, $e);
         }
     } else {
         $response->setStatus($code);
     }
     $this->response = $response;
     $status = $response->getStatus();
     $this->code = $status['code'];
     $this->message = $status['message'];
 }
예제 #3
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());
 }
 /**
  * The http status code for the error.
  *
  * @return int
  */
 function getHttpStatus()
 {
     return $this->response->getStatus();
 }