Skip to content

Commit e79b338

Browse files
committed
feat: added options for change default behaviour json depth formatter
1 parent 37445bc commit e79b338

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

app/Config/Format.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,13 @@ class Format extends BaseConfig
6161
'application/xml' => 0,
6262
'text/xml' => 0,
6363
];
64+
65+
/**
66+
* --------------------------------------------------------------------------
67+
* JSON Formatters Depth
68+
* --------------------------------------------------------------------------
69+
*
70+
* Additional options to adjust default depth JSON Encode.
71+
*/
72+
public int $jsonDepthOptions = 512;
6473
}

system/Format/JSONFormatter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ public function format($data)
3434
{
3535
$config = new Format();
3636

37+
$jsonDepth = $config->jsonDepthOptions ?? 512;
38+
3739
$options = $config->formatterOptions['application/json'] ?? JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES;
3840
$options |= JSON_PARTIAL_OUTPUT_ON_ERROR;
3941

4042
if (ENVIRONMENT !== 'production') {
4143
$options |= JSON_PRETTY_PRINT;
4244
}
4345

44-
$result = json_encode($data, $options, 512);
46+
$result = json_encode($data, $options, $jsonDepth);
4547

4648
if (! in_array(json_last_error(), [JSON_ERROR_NONE, JSON_ERROR_RECURSION], true)) {
4749
throw FormatException::forInvalidJSON(json_last_error_msg());

0 commit comments

Comments
 (0)