public function JsonResponse::__construct in Zircon Profile 8
Same name in this branch
- 8 vendor/symfony/http-foundation/JsonResponse.php \Symfony\Component\HttpFoundation\JsonResponse::__construct()
- 8 vendor/zendframework/zend-diactoros/src/Response/JsonResponse.php \Zend\Diactoros\Response\JsonResponse::__construct()
Same name and namespace in other branches
- 8.0 vendor/zendframework/zend-diactoros/src/Response/JsonResponse.php \Zend\Diactoros\Response\JsonResponse::__construct()
Create a JSON response with the given data.
Default JSON encoding is performed with the following options, which produces RFC4627-compliant JSON, capable of embedding into HTML.
- JSON_HEX_TAG
- JSON_HEX_APOS
- JSON_HEX_AMP
- JSON_HEX_QUOT
Parameters
mixed $data Data to convert to JSON.:
int $status Integer status code for the response; 200 by default.:
array $headers Array of headers to use at initialization.:
int $encodingOptions JSON encoding options to use.:
Throws
InvalidArgumentException if unable to encode the $data to JSON.
Overrides Response::__construct
File
- vendor/
zendframework/ zend-diactoros/ src/ Response/ JsonResponse.php, line 44
Class
- JsonResponse
- JSON response.
Namespace
Zend\Diactoros\ResponseCode
public function __construct($data, $status = 200, array $headers = [], $encodingOptions = 15) {
$body = new Stream('php://temp', 'wb+');
$body
->write($this
->jsonEncode($data, $encodingOptions));
$headers = $this
->injectContentType('application/json', $headers);
parent::__construct($body, $status, $headers);
}