‪TYPO3CMS  11.5
TYPO3\CMS\Core\Http\JsonResponse Class Reference
Inheritance diagram for TYPO3\CMS\Core\Http\JsonResponse:
TYPO3\CMS\Core\Http\Response TYPO3\CMS\Core\Http\Message

Public Member Functions

 __construct (?array $data=[], int $status=200, array $headers=[], int $encodingOptions=self::DEFAULT_JSON_FLAGS)
 
$this setPayload (array $data=[], int $encodingOptions=self::DEFAULT_JSON_FLAGS)
 
- ‪Public Member Functions inherited from ‪TYPO3\CMS\Core\Http\Response
 __construct ($body='php://temp', $statusCode=200, $headers=[], string $reasonPhrase='')
 
int getStatusCode ()
 
string getReasonPhrase ()
 
- ‪Public Member Functions inherited from ‪TYPO3\CMS\Core\Http\Message
string getProtocolVersion ()
 
array getHeaders ()
 
bool hasHeader ($name)
 
string[] getHeader ($name)
 
string getHeaderLine ($name)
 
Psr Http Message StreamInterface getBody ()
 
string filter ($value)
 
 validateHeaderName ($name)
 
bool isValidHeaderValue ($value)
 

Public Attributes

const DEFAULT_JSON_FLAGS = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES
 

Private Member Functions

 jsonEncode (array $data, int $encodingOptions)
 

Additional Inherited Members

- ‪Static Public Member Functions inherited from ‪TYPO3\CMS\Core\Http\Response
static withStatus ($code, $reasonPhrase='')
 
- ‪Static Public Member Functions inherited from ‪TYPO3\CMS\Core\Http\Message
static withProtocolVersion ($version)
 
static withHeader ($name, $value)
 
static withAddedHeader ($name, $value)
 
static withoutHeader ($name)
 
static withBody (StreamInterface $body)
 
- ‪Protected Member Functions inherited from ‪TYPO3\CMS\Core\Http\Message
 assertHeaders (array $headers)
 
array filterHeaders (array $originalHeaders)
 
bool arrayContainsOnlyStrings (array $data)
 
 validateHeaderValues (array $values)
 
- ‪Protected Attributes inherited from ‪TYPO3\CMS\Core\Http\Response
int $statusCode
 
string $reasonPhrase = ''
 
array $availableStatusCodes
 
- ‪Protected Attributes inherited from ‪TYPO3\CMS\Core\Http\Message
string $protocolVersion = '1.1'
 
array $headers = array( )
 
array $lowercasedHeaderNames = array( )
 
StreamInterface null $body
 

Detailed Description

Standard values for a JSON response

Highly inspired by ZF zend-diactoros

Note that this is not public API, use PSR-17 interfaces instead

Definition at line 27 of file JsonResponse.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Http\JsonResponse::__construct ( ?array  $data = [],
int  $status = 200,
array  $headers = [],
int  $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
array | null$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.

Definition at line 57 of file JsonResponse.php.

References TYPO3\CMS\Core\Http\Message\$body, TYPO3\CMS\Core\Http\Message\$headers, TYPO3\CMS\Core\Http\Message\hasHeader(), and TYPO3\CMS\Core\Http\JsonResponse\setPayload().

Member Function Documentation

◆ jsonEncode()

TYPO3\CMS\Core\Http\JsonResponse::jsonEncode ( array  $data,
int  $encodingOptions 
)
private

Encode the provided data to JSON.

Exceptions

Definition at line 96 of file JsonResponse.php.

Referenced by TYPO3\CMS\Core\Http\JsonResponse\setPayload().

◆ setPayload()

$this TYPO3\CMS\Core\Http\JsonResponse::setPayload ( array  $data = [],
int  $encodingOptions = self::DEFAULT_JSON_FLAGS 
)

Overrides the exiting content, takes an array as input

Parameters
array$data
int$encodingOptions
Returns
‪$this

Definition at line 84 of file JsonResponse.php.

References TYPO3\CMS\Core\Http\JsonResponse\jsonEncode().

Referenced by TYPO3\CMS\Core\Http\JsonResponse\__construct().

Member Data Documentation

◆ DEFAULT_JSON_FLAGS

const TYPO3\CMS\Core\Http\JsonResponse::DEFAULT_JSON_FLAGS = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES

Definition at line 38 of file JsonResponse.php.

Referenced by TYPO3\TestEid\Eid\EidAutoResponder\processRequest().