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

Require response to be a string or implements Stringable #21

Merged
merged 1 commit into from
Apr 23, 2023

Conversation

antonio-gg-dev
Copy link
Member

📚 Description

To improve DX, we should ensure that the responses are strings or implement the Stringable interface (which was added in version 8.0 of PHP).

This was already being done accidentally, but now the code makes sure of it and throws a very clear exception to the developer if this is not the case.

This allows for more flexibility, for example, if someone is doing a simple CRUD, they could directly respond with their models in their controllers as long as they implement the Stringable interface (leaving aside opinions on whether this is more or less correct).

🔖 Changes

  • Check if the response is a string or implements the Stringable interface.
  • An exception is thrown in case it doesn't.
  • Add new UnsupportedResponseTypeException.
  • Built-in responses now implements the Stringable interface.
  • Marginally improved the ñapa used to capture headers in the tests.

Copy link
Member

@Chemaclass Chemaclass left a comment

Choose a reason for hiding this comment

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

Great PR! Thank you

Copy link
Member

@JesusValeraDev JesusValeraDev left a comment

Choose a reason for hiding this comment

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

Small question, but nice PR! 🚀

@Chemaclass Chemaclass merged commit e791860 into main Apr 23, 2023
@Chemaclass Chemaclass deleted the stringable branch April 23, 2023 17:58
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.

3 participants