diff options
Diffstat (limited to 'lib/public')
-rw-r--r-- | lib/public/AppFramework/Http/JSONResponse.php | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/public/AppFramework/Http/JSONResponse.php b/lib/public/AppFramework/Http/JSONResponse.php index 4890d483cba..7551d264e73 100644 --- a/lib/public/AppFramework/Http/JSONResponse.php +++ b/lib/public/AppFramework/Http/JSONResponse.php @@ -23,6 +23,11 @@ class JSONResponse extends Response { * @var T */ protected $data; + /** + * Additional `json_encode` flags + * @var int + */ + protected $encodeFlags; /** @@ -30,12 +35,20 @@ class JSONResponse extends Response { * @param T $data the object or array that should be transformed * @param S $statusCode the Http status code, defaults to 200 * @param H $headers + * @param int $encodeFlags Additional `json_encode` flags * @since 6.0.0 + * @since 30.0.0 Added `$encodeFlags` param */ - public function __construct(mixed $data = [], int $statusCode = Http::STATUS_OK, array $headers = []) { + public function __construct( + mixed $data = [], + int $statusCode = Http::STATUS_OK, + array $headers = [], + int $encodeFlags = 0, + ) { parent::__construct($statusCode, $headers); $this->data = $data; + $this->encodeFlags = $encodeFlags; $this->addHeader('Content-Type', 'application/json; charset=utf-8'); } @@ -47,7 +60,7 @@ class JSONResponse extends Response { * @throws \Exception If data could not get encoded */ public function render() { - return json_encode($this->data, JSON_HEX_TAG | JSON_THROW_ON_ERROR, 2048); + return json_encode($this->data, JSON_HEX_TAG | JSON_THROW_ON_ERROR | $this->encodeFlags, 2048); } /** |