Skip to content

Commit 5ed7da2

Browse files
committed
feat: Allow additional flags in JsonDecoder
1 parent e3c603a commit 5ed7da2

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/JsonDecoder.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,29 @@
99

1010
final class JsonDecoder
1111
{
12-
public static function decode(string $json, bool $assoc = true): mixed
12+
public static function decode(string $json, bool $assoc = true, int $flags = 0): mixed
1313
{
1414
try {
15-
return json_decode($json, $assoc, 512, JSON_THROW_ON_ERROR);
15+
return json_decode($json, $assoc, 512, JSON_THROW_ON_ERROR | $flags);
1616
} catch (JsonException $exception) {
1717
throw InvalidJsonFormatException::wrappingException($exception);
1818
}
1919
}
2020

21-
public static function decodeSilently(string $json, bool $assoc = true): mixed
21+
public static function decodeSilently(string $json, bool $assoc = true, int $flags = 0): mixed
2222
{
2323
try {
24-
return self::decode($json, $assoc);
24+
return self::decode($json, $assoc, $flags);
2525
} catch (InvalidJsonFormatException) {
2626
return null;
2727
}
2828
}
2929

30-
public static function validate(string $json): bool
30+
/**
31+
* @phpstan-param 0|JSON_INVALID_UTF8_IGNORE $flags
32+
*/
33+
public static function validate(string $json, int $flags = 0): bool
3134
{
32-
return json_validate($json);
35+
return json_validate($json, 512, $flags);
3336
}
3437
}

0 commit comments

Comments
 (0)