Skip to content

Support to custom response class.#17

Merged
Sammyjo20 merged 30 commits intosaloonphp:mainfrom
yurirnascimento:main
Jan 28, 2022
Merged

Support to custom response class.#17
Sammyjo20 merged 30 commits intosaloonphp:mainfrom
yurirnascimento:main

Conversation

@yurirnascimento
Copy link
Copy Markdown
Contributor

Related to #11

I added the possibility to inform a custom class to return as a response in addition to the default SaloonResponse.

Changes:

  • Change the SaloonRequestInterface to have getResponseClass method.
  • Create a folder to contain all custom responses
  • Create a invalid response to test
  • Creeate a CustoUserResponse
  • Create a UserResponse to show how to use

Added tests:

  • check if the class extends SaloonResponse
  • check if the response is the class informed
  • check if the request with custom response work

I tried to keep the existing coding style.

hope this can help.

@Sammyjo20
Copy link
Copy Markdown
Member

This PR looks great, thank you @yurirnascimento. I need to take a proper look at the code on my laptop but thanks for contributing this.

Copy link
Copy Markdown
Member

@Sammyjo20 Sammyjo20 left a comment

Choose a reason for hiding this comment

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

Looks good, I think we should have a connector that can be defined on the response too, which should run the same code as the request. So many could be dedicated to a trait like "HasCustomResponses"

Connector need to implement getResponseClass
Trait for implement getResponseClass
Get default ResponseClass from connector
Use HasResponseClass with implements getResponseClass
Fix Docblock ReflectionException on createResponse
Change to implement getResponseClass and be used in Connector or Request.
Remove the getResponseClass method implementation to use HasResponseClass trait.
add tests to custom response in connector
Copy link
Copy Markdown
Member

@Sammyjo20 Sammyjo20 left a comment

Choose a reason for hiding this comment

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

This looks fantastic! Happy with the code, there's some formatting things I'd like to quickly fix but I'll write a commit for you, but functionality wise this looks great. I will also draft some documentation before the release.

Thanks for the hard work @yurirnascimento and thank you everyone else for helping with the idea.

Copy link
Copy Markdown
Member

@Sammyjo20 Sammyjo20 left a comment

Choose a reason for hiding this comment

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

Sorry just a couple other things

@Sammyjo20 Sammyjo20 linked an issue Jan 28, 2022 that may be closed by this pull request
@Sammyjo20
Copy link
Copy Markdown
Member

Thanks for this awesome PR @yurirnascimento! Going to write up some documentation now... 💅

@Sammyjo20 Sammyjo20 merged commit 15c169e into saloonphp:main Jan 28, 2022
@Sammyjo20
Copy link
Copy Markdown
Member

Written up some docs in the “Responses” section.

@yurirnascimento
Copy link
Copy Markdown
Contributor Author

I just read it and it was great, excellent work.

@Sammyjo20
Copy link
Copy Markdown
Member

You too!! 🚀

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 casting to DTO

2 participants