Skip to content

feat(support): add json encode/decode to array and string utilities #1396

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

Merged
merged 4 commits into from
Jul 12, 2025

Conversation

xHeaven
Copy link
Contributor

@xHeaven xHeaven commented Jul 9, 2025

Closes #1388

@brendt
Copy link
Member

brendt commented Jul 10, 2025

Perfect! One thing I wonder about is whether we can automatically determine mutability based on the class

So ImmutableString > ImmutableArray, MutableArray > MutableString, etc.

@innocenzi do we already have a detection method for this in place? I actually don't think we do?

If we don't, then let's not overcomplicate this PR. I'd remove the mutable parameter, always return the Immutable version (I believe this is consistent with the rest of the support helpers) and solve the mutability problem as a separate PR.

Copy link
Member

@innocenzi innocenzi left a comment

Choose a reason for hiding this comment

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

I don't think we should have a mutable option, we can always call toMutableArray and toMutableString on the returned instance

@innocenzi innocenzi changed the title feat(support): implement json encode and decode functions for arr() and str() respectively feat(support): add json encode/decode to array and string utilities Jul 10, 2025
@innocenzi
Copy link
Member

Also, how about dropping json from the method name? arr()->encode() and str()->decode()?

If not, I would prefer encodeJson and decodeJson instead of the other way around

@brendt
Copy link
Member

brendt commented Jul 10, 2025

Let's

  • use encodeJson and decodeJson
  • drop the mutable option and always return the immutable variant

@xHeaven
Copy link
Contributor Author

xHeaven commented Jul 10, 2025

@brendt @innocenzi take a look 👀

@brendt brendt merged commit 978bba2 into tempestphp:main Jul 12, 2025
69 checks passed
@xHeaven xHeaven deleted the json-handling branch July 14, 2025 11:27
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.

Add str()->jsonDecode and arr()->jsonDecode
3 participants