Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove json utils methods and json custom exception #2133

Open
wants to merge 2 commits into
base: 8.x
Choose a base branch
from

Conversation

deguif
Copy link
Collaborator

@deguif deguif commented Dec 7, 2022

No description provided.

@deguif deguif force-pushed the remove-json-util branch 2 times, most recently from d7fd542 to 114e5ca Compare December 7, 2022 13:54
@sidz
Copy link
Contributor

sidz commented Dec 7, 2022

my 2 cents: what about to no remove JSON class and improve it instead to smth like:

class JsonEncoder
{
    private function __construct()
    {
    }

    public static function encode(mixed $value, int $flags = null, int $maxDepth = 512): string
    {
        $flags ??= \JSON_HEX_TAG | \JSON_HEX_APOS | \JSON_HEX_AMP | \JSON_HEX_QUOT | \JSON_PRESERVE_ZERO_FRACTION;

        try {
            return json_encode($value, $flags | \JSON_THROW_ON_ERROR, $maxDepth);
        } catch (\JsonException $e) {
            throw new InvalidArgumentException('Invalid value for "json" option: '.$e->getMessage());
        }
    }

and the same for json_decode.

The idea is pretty simple - tons of json_encode(decode) around the codebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants