__construct() public method

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
public __construct ( mixed $data, integer $status = 200, array $headers = [], integer $encodingOptions = self::DEFAULT_JSON_FLAGS )
$data mixed Data to convert to JSON.
$status integer Integer status code for the response; 200 by default.
$headers array Array of headers to use at initialization.
$encodingOptions integer JSON encoding options to use.
Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function __construct(Document $document, $status = 200, array $headers = [], $encodingOptions = 15)
 {
     $headers['content-type'] = 'application/vnd.api+json';
     // The call to jsonSerialize prevents rare issues with json_encode() failing with a
     // syntax error even though Document implements the JsonSerializable interface.
     // See https://github.com/flarum/core/issues/685
     parent::__construct($document->jsonSerialize(), $status, $headers, $encodingOptions);
 }
 /**
  * Constructor
  *
  * @todo Customize according to project
  * @param array $errors Errors
  */
 public function __construct(array $errors)
 {
     parent::__construct(['status' => 'error', 'errors' => $errors], 422);
 }
 /**
  * @param mixed $code
  * @param int $message
  */
 public function __construct($code, $message)
 {
     $responseData = ['code' => $code, 'message' => $message, 'reference' => ''];
     parent::__construct($responseData, $code);
 }
 /**
  * Create an empty response with the 404 status code
  *
  * @param mixed $data Explanation
  * @param array $headers Headers for the response, if any.
  */
 public function __construct($data, array $headers = [])
 {
     parent::__construct($data, 404, $headers);
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function __construct(Document $document, $status = 200, array $headers = [], $encodingOptions = 15)
 {
     $headers['content-type'] = 'application/vnd.api+json';
     parent::__construct($document, $status, $headers, $encodingOptions);
 }
Esempio n. 6
0
 /**
  * JsonResponse overloaded Constructor to assign JSON-API Content-Type
  * and require JsonApi\Document instance as body
  */
 public function __construct(Document $document, $status = 200, array $headers = [], $encodingOptions = self::DEFAULT_JSON_FLAGS)
 {
     $headers['Content-Type'] = 'application/vnd.api+json';
     parent::__construct($document->toArray(), $status, $headers, $encodingOptions);
 }