Example #1
0
 /**
  * @param int $status_code OPTIONAL Defaults to `200`.
  * @param boolean $read_all_buffers OPTIONAL Whether to get and clean the content of all open buffers.
  *                                  Defaults to `true`.
  */
 public static function createFromBuffer($status_code = 200, $read_all_buffers = true)
 {
     # Get our body from the buffer
     $body = "";
     while (($more_body = ob_get_clean()) !== false) {
         $body .= $more_body;
         if (!$read_all_buffers) {
             break;
         }
     }
     $response = new Response($body, $status_code);
     # Add all headers in the buffer and guess response encoding.
     $response->addSentHeaders();
     foreach ($response->getHeaders() as $header) {
         if (preg_match("/^Content-Type:.+;\\s*charset=(.+)\$/i", $header, $matches) === 0) {
             continue;
         }
         $response->setEncoding($matches[1]);
     }
     return $response;
 }