Webiny\Component\Http\Response::__construct PHP Method

__construct() public method

Constructs the Response object.
public __construct ( string $content = '', integer $statusCode = 200, array $headers = [] )
$content string Content that will be attached to the response.
$statusCode integer HTTP status code that will be sent back to the user.
$headers array Additional headers that should be attached to the response.
    public function __construct($content = '', $statusCode = 200, $headers = [])
    {
        $this->setContent($content);
        $this->setStatusCode($statusCode);
        $this->headers = $this->arr($headers);
        $this->cacheControl = new CacheControl();
        $this->cacheControl->setAsDontCache();
    }

Usage Example

Esempio n. 1
0
 /**
  * Base constructor.
  *
  * @param string|array|ArrayObject $content     Json content.
  * @param array                    $headers     Headers to attach to the response.
  * @param bool                     $prettyPrint Should we use JSON_PRETTY_PRINT to nicely format the output.
  */
 public function __construct($content, $headers = [], $prettyPrint = false)
 {
     if (StdObjectWrapper::isArrayObject($content)) {
         $content = $this->jsonEncode($content->val(), $prettyPrint ? JSON_PRETTY_PRINT : 0);
     } else {
         if ($this->isArray($content) || $this->isObject($content)) {
             $content = $this->jsonEncode($content, $prettyPrint ? JSON_PRETTY_PRINT : 0);
         }
     }
     parent::__construct($content, 200, $headers);
     $this->setContentType('application/json');
 }