Skip to content

Commit

Permalink
Removed force object from default json response
Browse files Browse the repository at this point in the history
  • Loading branch information
shudd3r committed Aug 31, 2022
1 parent d09aa07 commit 926cd8c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public static function xml(string $xml, int $statusCode = 200): self
}

/**
* There's a XOR operator between $defaultEncode and $encodeOptions,
* which means that if option is set in both provided and default it
* There's a XOR operator between $defaultOptions and $encodeOptions,
* which means that if an option is set in both provided and default it
* will be switched off.
*
* @param array $data
Expand All @@ -76,11 +76,10 @@ public static function xml(string $xml, int $statusCode = 200): self
*
* @return self
*/
public static function json(array $data, int $statusCode = 200, $encodeOptions = 0): self
public static function json(array $data, int $statusCode = 200, int $encodeOptions = 0): self
{
$defaultEncode = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT |
JSON_UNESCAPED_SLASHES | JSON_FORCE_OBJECT;
$serialized = json_encode($data, $defaultEncode ^ $encodeOptions);
$defaultOptions = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES;
$serialized = $data ? json_encode($data, $defaultOptions ^ $encodeOptions) : '{}';

return new self($statusCode, Stream::fromBodyString($serialized), ['Content-Type' => 'application/json']);
}
Expand Down

0 comments on commit 926cd8c

Please sign in to comment.