cvs: pear /HTTP_Client Client.php package.xml

From: Date: Sat, 17 Jan 2004 13:57:06 +0000
Subject: cvs: pear /HTTP_Client Client.php package.xml
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-15726@lists.php.net to get a copy of this message
avb Sat Jan 17 08:57:06 2004 EDT Modified files: /pear/HTTP_Client Client.php package.xml Log: Added setMaxRedirects() Added possibility to propagate Listeners to HTTP_Request objects Added support for file uploads Updated release notes for 0.2 Index: pear/HTTP_Client/Client.php diff -u pear/HTTP_Client/Client.php:1.2 pear/HTTP_Client/Client.php:1.3 --- pear/HTTP_Client/Client.php:1.2 Fri Dec 12 10:53:23 2003 +++ pear/HTTP_Client/Client.php Sat Jan 17 08:57:06 2004 @@ -16,7 +16,7 @@ // | Author: Alexey Borzov <avb@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Client.php,v 1.2 2003/12/12 15:53:23 avb Exp $ +// $Id: Client.php,v 1.3 2004/01/17 13:57:06 avb Exp $ require_once 'HTTP/Request.php'; require_once 'HTTP/Client/CookieManager.php'; @@ -29,7 +29,7 @@ * * @package HTTP_Client * @author Alexey Borzov <avb@php.net> - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ class HTTP_Client { @@ -76,6 +76,12 @@ var $_listeners = array(); /** + * Whether the listener should be propagated to Request objects + * @var array + */ + var $_propagate = array(); + + /** * Constructor * * @access public @@ -95,6 +101,22 @@ /** + * Sets the maximum redirects that will be processed. + * + * Setting this to 0 disables redirect processing. If not 0 and the + * number of redirects in a request is bigger than this number, then an + * error will be raised. + * + * @access public + * @param int Max number of redirects to process + */ + function setMaxRedirects($value) + { + $this->_maxRedirects = $value; + } + + + /** * Creates a HTTP_Request objects, applying all the necessary defaults * * @param string URL @@ -110,6 +132,11 @@ $req->addHeader($name, $value); } $this->_cookieManager->passCookies($req); + foreach ($this->_propagate as $id => $propagate) { + if ($propagate) { + $req->attach($this->_listeners[$id]); + } + } return $req; } @@ -159,11 +186,13 @@ * @param string URL * @param mixed Data to send * @param boolean Whether the data is already urlencoded + * @param array Files to upload. Elements of the array should have the form: + * array(name, filename(s)[, content type]), see HTTP_Request::addFile() * @access public * @return integer HTTP response code * @throws PEAR_Error */ - function post($url, $data, $preEncoded = false) + function post($url, $data, $preEncoded = false, $files = array()) { $request =& $this->_createRequest($url, HTTP_REQUEST_METHOD_POST); if (is_array($data)) { @@ -173,6 +202,12 @@ } else { $request->addRawPostData($data, $preEncoded); } + foreach ($files as $fileData) { + $res = call_user_func_array(array(&$request, 'addFile'), $fileData); + if (PEAR::isError($res)) { + return $res; + } + } return $this->_performRequest($request); } @@ -248,7 +283,11 @@ if (302 == $code || 303 == $code) { return $this->get($url); } else { - return $this->post($url, $request->_postData, true); + $postFiles = array(); + foreach ($request->_postFiles as $name => $data) { + $postFiles[] = array($name, $data['name'], $data['type']); + } + return $this->post($url, $request->_postData, true, $postFiles); } case HTTP_REQUEST_METHOD_HEAD: return (303 == $code? $this->get($url): $this->head($url)); @@ -320,15 +359,18 @@ * the object's events * * @param object HTTP_Request_Listener instance to attach + * @param boolean Whether the listener should be attached to the + * created HTTP_Request objects * @return boolean whether the listener was successfully attached * @access public */ - function attach(&$listener) + function attach(&$listener, $propagate = false) { if (!is_a($listener, 'HTTP_Request_Listener')) { return false; } $this->_listeners[$listener->getId()] =& $listener; + $this->_propagate[$listener->getId()] = $propagate; return true; } @@ -346,7 +388,7 @@ !isset($this->_listeners[$listener->getId()])) { return false; } - unset($this->_listeners[$listener->getId()]); + unset($this->_listeners[$listener->getId()], $this->_propagate[$listener->getId()]); return true; } Index: pear/HTTP_Client/package.xml diff -u pear/HTTP_Client/package.xml:1.3 pear/HTTP_Client/package.xml:1.4 --- pear/HTTP_Client/package.xml:1.3 Fri Dec 12 10:54:03 2003 +++ pear/HTTP_Client/package.xml Sat Jan 17 08:57:06 2004 @@ -26,11 +26,14 @@ <release> <version>0.2</version> <state>beta</state> - <date>2003-12-??</date> + <date>2004-01-??</date> <notes> * Depend on most recent version of HTTP_Request - HTTP_Client_Listener is deprecated in favor of HTTP_Request_Listener + - Added possibilty to attach Listeners to created HTTP_Request objects + - Added support for file uploads in post() method * Better handling of secure cookies (thanks to Denis Malinovsky) +* Added setMaxRedirects() method </notes> <filelist> <dir name="/" baseinstalldir="HTTP">

« previous php.pear.cvs (#15726) next »