private function convert(Response $response)
 {
     foreach ($this->converters as $converter) {
         if ($converter->support($response->getContentType())) {
             return $converter->write($response->getPayload());
         }
         throw new \UnknowConverter($response->getContentType());
     }
     return $response;
 }
Example #2
0
 /**
  * Sets HTTP response headers and writes out the buffer.
  * @param Response $response Response to write out and to send to the client
  */
 protected static function output(Response $response)
 {
     header("HTTP/1.1 " . $response->getStatus());
     if ($response->getContentType() != null && $response->getCharacterEncoding() != null) {
         header("Content-Type: " . $response->getContentType() . "; charset=" . $response->getCharacterEncoding());
     }
     if ($response->getBuffer() != null) {
         print $response->getBuffer();
     }
     // exit
 }
Example #3
0
 /**
  * Terminates application.
  *
  * Renders content or excute redirecting
  *
  * @param Response $response
  */
 public function terminate(Response $response)
 {
     if ($response->getRedirectUrl() === null) {
         header("Content-Type: {$response->getContentType()}; charset=utf-8");
         http_response_code($response->getStatusCode());
         $response->display();
     } else {
         header("Location: {$response->getRedirectUrl()}");
     }
     exit;
 }
Example #4
0
 public static function fromResponse(Response $response)
 {
     return new self($response->getBody(), $response->getContentType());
 }