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. |
/** * 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'); }