__construct() public method

Produces an HTML response with a Content-Type of text/html and a default status of 200.
public __construct ( string | Psr\Http\Message\StreamInterface $html, integer $status = 200, array $headers = [] )
$html string | Psr\Http\Message\StreamInterface HTML or stream for the message body.
$status integer Integer status code for the response; 200 by default.
$headers array Array of headers to use at initialization.
Example #1
0
 /**
  * @param mixed $data The data to respond with. Will be json_encoded first.
  * @param int $status Status code, typically 200 (the default).
  * @param array $headers Optional custom headers.
  */
 public function __construct($data, $status = 200, array $headers = [])
 {
     $json = json_encode($data);
     $headers['content-type'] = 'application/json; charset=utf-8';
     $headers['access-control-allow-methods'] = 'GET, POST, OPTIONS';
     $headers['access-control-allow-credentials'] = 'true';
     $headers['access-control-allow-headers'] = "Content-Type, Authorization, Content-Length, X-Requested-With";
     if (isset($_SERVER['HTTP_ORIGIN'])) {
         $headers['access-control-allow-origin'] = $_SERVER['HTTP_ORIGIN'];
     }
     parent::__construct($json, $status, $headers);
 }