Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 0.2.0
-
Component/s: Zend_Http_Client, Zend_Uri
-
Labels:None
Description
I've made some changes to Zend_Uri_Http and added a query string parameter to Zend_Http_Client::get(). I've also removed Zend_Uri_Http::setQueryArray() and Zend_Uri_Http::setQueryString() and replaced them with a simpler Zend_Uri_Http::setQuery() function.
This takes care of the @todo in Zend_Http_Client::get().
// Zend_Uri_Http::setQuery() public function setQuery($query) { $queryArray = array(); if (is_array($query)) { $queryArray = $query; } else if (is_string($query)) { parse_str($query, $queryArray); } if (count($queryArray)) { $query = http_build_query($queryArray, '', '&'); } else { throw new Zend_Uri_Exception('Invalid query'); } if ($this->validateQuery($query)) { $this->_query = $query; } }
I made the query string the first parameter because a) I didn't think many people would have set $redirectMax explicitly, and b) it is consistent with post(). If someone needs to set $redirectMax it's easier to set the query to NULL than trying to come up with a $redirectMax each time you need to set a query.
// Zend_Http_Client::get() /** * Send a GET HTTP Request * * @param array|string $arguments Arguments to pass in the query string * @param int $redirectMax Maximum number of HTTP redirections followed * @return Zend_Http_Response */ public function get($query = NULL, $redirectMax = 5) { if (!is_null($query)) { $this->_uri->setQuery($query); }
And on line 105:
$this->_uri->setQuery($query);
I prefer not to put too much effort on the Zend_Http_Client as it is going to be replaced by the incubator Zend_Http_Client which is a complete rewrite.
Do you think this issue concers the new Http_Client as well? This one has easier access to GET parameters and you could either set them individually using $client->setParameterGet('foo', 'baz'), or directly access the query string by doing this:
$client->getUri()->setQuery('foo=baz');I'm not sure if any further changes are needed. Let me know what you think.
$client->getUri()->setQuery('foo=baz');