Zend Framework  3.0
Public Member Functions | Public Attributes | List of all members
JsonResponse Class Reference

JSON response. More...

Public Member Functions

 __construct ($data, $status=200, array $headers=[], $encodingOptions=self::DEFAULT_JSON_FLAGS)
 Create a JSON response with the given data.
 
- Public Member Functions inherited from Response
 __construct ($body= 'php://memory', $status=200, array $headers=[])
 
 getStatusCode ()
 {}
 
 getReasonPhrase ()
 {}
 
 withStatus ($code, $reasonPhrase= '')
 {}
 

Public Attributes

const DEFAULT_JSON_FLAGS = 79
 Default flags for json_encode; value of:
 

Detailed Description

JSON response.

Allows creating a response by passing data to the constructor; by default, serializes the data to JSON, sets a status code of 200 and sets the Content-Type header to application/json.

Constructor & Destructor Documentation

__construct (   $data,
  $status = 200,
array  $headers = [],
  $encodingOptions = self::DEFAULT_JSON_FLAGS 
)

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
  • JSON_UNESCAPED_SLASHES
Parameters
mixed$dataData to convert to JSON.
int$statusInteger status code for the response; 200 by default.
array$headersArray of headers to use at initialization.
int$encodingOptionsJSON encoding options to use.
Exceptions
InvalidArgumentExceptionif unable to encode the $data to JSON.

Member Data Documentation

const DEFAULT_JSON_FLAGS = 79

Default flags for json_encode; value of:

JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES

int