ZF-11165: Make Zend_Http_Client response class injectable/stubbable
Description
The response implementation class of Zend_Http_Client is strictly coupled to Zend_Http_Response. Introducing a factory method that is overridable improves flexibility and extensibility of the class, and providing custom
Zend_Http_Response currently doesn't employ an interface, so forcing a subclass of Zend_Http_Response makes sense, though more refactoring should be needed to simply have a contract based on a Zend_Http_ResponseInterface.
Index: Zend/Http/Client.php
===================================================================
--- Zend/Http/Client.php (revision 4954)
+++ Zend/Http/Client.php (working copy)
@@ -1003,7 +1003,10 @@
$response->setCleanup(true);
}
} else {
- $response = Zend_Http_Response::fromString($response);
+ $response = $this->_createResponseFromString($response);
+ if(! $response instanceof Zend_Http_Response) {
+ throw new UnexpectedValueException(get_class($this) . '::_createResponseFromString() should return Zend_Http_Response instance');
+ }
}
if ($this->config['storeresponse']) {
@@ -1067,7 +1070,18 @@
return $response;
}
+
/**
+ * Composes a Zend_Http_Response object based on the passed response string
+ *
+ * @return Zend_Http_Response
+ */
+ protected function _createResponseFromString($responseString)
+ {
+ return Zend_Http_Response::fromString($responseString);
+ }
+
+ /**
* Prepare the request headers
*
* @return array
revision doesn't match, btw, it is the revision of my own svn project's repository.
Comments
Posted by Frank Brückner (frosch) on 2013-02-10T16:22:35.000+0000
Can someone create a patch and unit tests?
Maybe Gerard?