* @author Martin Jansen <mj@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id: Downloader.php 313024 2011-07-06 19:51:24Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.3.0
*/
* @author Martin Jansen <mj@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: 1.9.4
+ * @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.3.0
*/
*/
var $_downloadDir;
+ /**
+ * List of methods that can be called both statically and non-statically.
+ * @var array
+ */
+ protected static $bivalentMethods = array(
+ 'setErrorHandling' => true,
+ 'raiseError' => true,
+ 'throwError' => true,
+ 'pushErrorHandling' => true,
+ 'popErrorHandling' => true,
+ 'downloadHttp' => true,
+ );
+
/**
* @param PEAR_Frontend_*
* @param array
* @param PEAR_Config
*/
- function PEAR_Downloader(&$ui, $options, &$config)
+ function __construct($ui = null, $options = array(), $config = null)
{
- parent::PEAR_Common();
+ parent::__construct();
$this->_options = $options;
- $this->config = &$config;
- $this->_preferredState = $this->config->get('preferred_state');
+ if ($config !== null) {
+ $this->config = &$config;
+ $this->_preferredState = $this->config->get('preferred_state');
+ }
$this->ui = &$ui;
if (!$this->_preferredState) {
// don't inadvertantly use a non-set preferred_state
$this->_preferredState = null;
}
- if (isset($this->_options['installroot'])) {
- $this->config->setInstallRoot($this->_options['installroot']);
+ if ($config !== null) {
+ if (isset($this->_options['installroot'])) {
+ $this->config->setInstallRoot($this->_options['installroot']);
+ }
+ $this->_registry = &$config->getRegistry();
}
- $this->_registry = &$config->getRegistry();
if (isset($this->_options['alldeps']) || isset($this->_options['onlyreqdeps'])) {
$this->_installed = $this->_registry->listAllPackages();
* @param PEAR_Downloader
* @return PEAR_Downloader_Package
*/
- function &newDownloaderPackage(&$t)
+ function newDownloaderPackage(&$t)
{
if (!class_exists('PEAR_Downloader_Package')) {
require_once 'PEAR/Downloader/Package.php';
}
- $a = &new PEAR_Downloader_Package($t);
+ $a = new PEAR_Downloader_Package($t);
return $a;
}
if (!class_exists('PEAR_Dependency2')) {
require_once 'PEAR/Dependency2.php';
}
- $z = &new PEAR_Dependency2($c, $i, $p, $s);
+ $z = new PEAR_Dependency2($c, $i, $p, $s);
return $z;
}
$channelschecked = array();
// convert all parameters into PEAR_Downloader_Package objects
foreach ($params as $i => $param) {
- $params[$i] = &$this->newDownloaderPackage($this);
+ $params[$i] = $this->newDownloaderPackage($this);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$err = $params[$i]->initialize($param);
PEAR::staticPopErrorHandling();
require_once 'System.php';
}
- $curchannel = &$this->_registry->getChannel($params[$i]->getChannel());
+ $curchannel = $this->_registry->getChannel($params[$i]->getChannel());
if (PEAR::isError($curchannel)) {
PEAR::staticPopErrorHandling();
return $this->raiseError($curchannel);
$a = $this->downloadHttp($url, $this->ui, $dir, null, $curchannel->lastModified());
PEAR::staticPopErrorHandling();
- if (PEAR::isError($a) || !$a) {
+ if ($a === false) {
+ //channel.xml not modified
+ break;
+ } else if (PEAR::isError($a)) {
// Attempt fallback to https automatically
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$a = $this->downloadHttp('https://' . $mirror .
} while (false);
}
- $chan = &$this->_registry->getChannel($parr['channel']);
+ $chan = $this->_registry->getChannel($parr['channel']);
if (PEAR::isError($chan)) {
return $chan;
}
$curchannel = $this->config->get('default_channel');
if (isset($dep['uri'])) {
$xsdversion = '2.0';
- $chan = &$this->_registry->getChannel('__uri');
+ $chan = $this->_registry->getChannel('__uri');
if (PEAR::isError($chan)) {
return $chan;
}
} while (false);
}
- $chan = &$this->_registry->getChannel($remotechannel);
+ $chan = $this->_registry->getChannel($remotechannel);
if (PEAR::isError($chan)) {
return $chan;
}
}
if (isset($dep['uri'])) {
- $info = &$this->newDownloaderPackage($this);
+ $info = $this->newDownloaderPackage($this);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$err = $info->initialize($dep);
PEAR::staticPopErrorHandling();
* use false to return the header values from this download
* @param false|array $accept Accept headers to send
* @param false|string $channel Channel to use for retrieving authentication
- * @return string|array Returns the full path of the downloaded file or a PEAR
- * error on failure. If the error is caused by
- * socket-related errors, the error object will
- * have the fsockopen error code available through
- * getCode(). If caching is requested, then return the header
- * values.
+ * @return mixed Returns the full path of the downloaded file or a PEAR
+ * error on failure. If the error is caused by
+ * socket-related errors, the error object will
+ * have the fsockopen error code available through
+ * getCode(). If caching is requested, then return the header
+ * values.
+ * If $lastmodified was given and the there are no changes,
+ * boolean false is returned.
*
* @access public
*/
- function downloadHttp($url, &$ui, $save_dir = '.', $callback = null, $lastmodified = null,
- $accept = false, $channel = false)
- {
+ public static function _downloadHttp(
+ $object, $url, &$ui, $save_dir = '.', $callback = null, $lastmodified = null,
+ $accept = false, $channel = false
+ ) {
static $redirect = 0;
// always reset , so we are clean case of error
$wasredirect = $redirect;
$port = isset($info['port']) ? $info['port'] : null;
$path = isset($info['path']) ? $info['path'] : null;
- if (isset($this)) {
- $config = &$this->config;
+ if ($object !== null) {
+ $config = $object->config;
} else {
$config = &PEAR_Config::singleton();
}
}
$request .= $ifmodifiedsince .
- "User-Agent: PEAR/1.9.4/PHP/" . PHP_VERSION . "\r\n";
+ "User-Agent: PEAR/1.10.1/PHP/" . PHP_VERSION . "\r\n";
- if (isset($this)) { // only pass in authentication for non-static calls
+ if ($object !== null) { // only pass in authentication for non-static calls
$username = $config->get('username', null, $channel);
$password = $config->get('password', null, $channel);
if ($username && $password) {
}
$redirect = $wasredirect + 1;
- return $this->downloadHttp($headers['location'],
+ return static::_downloadHttp($object, $headers['location'],
$ui, $save_dir, $callback, $lastmodified, $accept);
}
}
return $dest_file;
}
-}
\ No newline at end of file
+}