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

JsonNormalizer accepting json_encode flags #512

Merged
merged 12 commits into from
Apr 4, 2024

Conversation

boesing
Copy link
Contributor

@boesing boesing commented Mar 31, 2024

As discussed in #476, this PR introduces a new JsonNormalizer#withOptions method accepting the following JSON_* constant values as an integer bitmask:

  • JSON_HEX_QUOT
  • JSON_HEX_TAG
  • JSON_HEX_AMP
  • JSON_HEX_APOS
  • JSON_INVALID_UTF8_IGNORE
  • JSON_INVALID_UTF8_SUBSTITUTE
  • JSON_NUMERIC_CHECK
  • JSON_PRESERVE_ZERO_FRACTION
  • JSON_UNESCAPED_LINE_TERMINATORS
  • JSON_UNESCAPED_SLASHES
  • JSON_UNESCAPED_UNICODE

Since we should always enable JSON_THROW_ON_ERROR, I haven't added that one to the possible constants as it is enabled by-default.

Closes #476

@boesing boesing force-pushed the feature/normalizer-json-flags branch 2 times, most recently from 2f321fd to 5ccbaad Compare March 31, 2024 22:15
@boesing

This comment was marked as outdated.

This allows the JSON normalizer to accept some `JSON_*` constant options to be passed to `json_encode` via `flags` option.

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
@boesing boesing force-pushed the feature/normalizer-json-flags branch from 5ccbaad to e0eec68 Compare March 31, 2024 22:33
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
@boesing
Copy link
Contributor Author

boesing commented Mar 31, 2024

FYI: This adds additional time to the static analysis checks due to the int-mask-of.

romm added 5 commits April 1, 2024 10:44
This annotation leads to severe performance issues when running PHPStan
analysis, also this annotation does not work well with PHPStan,
therefore we prefer to avoid it.
Also makes the property private, we can force-access its value in tests
where needed.
This class is internal and always instantiated by `JsonNormalizer` which
already filters the bitmask.
@romm
Copy link
Member

romm commented Apr 1, 2024

@boesing excellent work, thank you for the contribution!

I pushed some changes, I'll let you review them and comment if needed.

When it's ready, let's ship it! 🚀

@romm romm mentioned this pull request Apr 1, 2024
);

// `$lowerManhattanAsJson` is a valid JSON string representing the data:
// {"longitude":"40.7128","latitude":-74.0000}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, somehow the longitude got string here. need to change this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

* );
*
* // `$lowerManhattanAsJson` is a valid JSON string representing the data:
* // {"longitude":"40.7128","latitude":-74.0000}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

longitude shouldnt be string here as well

@romm
Copy link
Member

romm commented Apr 2, 2024

@boesing just updated after #476 (comment)

Waiting for your review before merging!

@boesing
Copy link
Contributor Author

boesing commented Apr 2, 2024

LGTM! Thanks for talking over. ☺️

@romm romm merged commit cd5df97 into CuyZ:master Apr 4, 2024
11 checks passed
@romm
Copy link
Member

romm commented Apr 4, 2024

Thank you for this excellent contribution @boesing!

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.

Normalizer: float precision
3 participants