-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
ResponseFactory alternative to response objects needing Guzzle interface #375
Conversation
@@ -91,6 +92,20 @@ protected function handleParsing(CommandInterface $command, Response $response, | |||
*/ | |||
protected function parseClass(CommandInterface $command) | |||
{ | |||
$responseFactory = $command->getOperation()->getResponseFactory(); | |||
|
|||
if ($responseFactory != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this part and the section of code below this are very similar. Can you take a crack at refactoring this to remove some of the code duplication? I think it would be fine to remove the ResponseFactoryException and just throw a ResponsClassException for both error cases.
Thanks for the PR! This looks like a really good start. I have a couple requests:
responseFactory is good.
I can take a look at the inferResponseType() method after the PR is merged to attempt to clean it up a bit. I'd like the most common cases checked first, followed by the least common.
The unit tests look good. I'll take a closer look before merging and after these changes are completed. |
@Danack I've been thinking about this implementation and had a different train of thought. This implementation still enforces tight restrictions on how domain specific objects are created. I am going to submit a PR that implements custom response class creation using an event based system rather than adding a new custom attribute to the service description. Let me know what you think. |
Moot. |
Hi Michael,
Here is a pull request to add a 'responseFactory' option to both the service description and individual operations. There's a couple of things which probably need reviewing before merging.
I went with
responseFactory
as it's shorter but it looks slightly odd when callingsetResponseFactory
and passing in a string rather than a class instance.2 .There's a couple of bits of code that were already a bit 'hairy' which have gotten even more complicated.
Operation::inferResponseType() is one and in Operation::__construct() the lines:
if (!$this->responseClass && !$this->responseFactory) {
and below are definitely quite complicated. Should I attempt to refactor them?
I've added some unit tests for the added functionality, but I'm not a unit tester expert so if you think there's any other tests that are missing please let me know.
cheers
Dan