Updated PEAR and PEAR packages.
[timetracker.git] / WEB-INF / lib / pear / PEAR / Downloader.php
index 730df0b..6d6cdd7 100644 (file)
@@ -12,7 +12,6 @@
  * @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
  */
@@ -39,7 +38,7 @@ define('PEAR_INSTALLER_ERROR_NO_PREF_STATE', 2);
  * @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
  */
@@ -140,27 +139,44 @@ class PEAR_Downloader extends PEAR_Common
      */
     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();
@@ -235,12 +251,12 @@ class PEAR_Downloader extends PEAR_Common
      * @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;
     }
 
@@ -256,7 +272,7 @@ class PEAR_Downloader extends PEAR_Common
         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;
     }
 
@@ -274,7 +290,7 @@ class PEAR_Downloader extends PEAR_Common
         $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();
@@ -315,7 +331,7 @@ class PEAR_Downloader extends PEAR_Common
                             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);
@@ -331,7 +347,10 @@ class PEAR_Downloader extends PEAR_Common
                         $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 .
@@ -806,7 +825,7 @@ class PEAR_Downloader extends PEAR_Common
             } while (false);
         }
 
-        $chan = &$this->_registry->getChannel($parr['channel']);
+        $chan = $this->_registry->getChannel($parr['channel']);
         if (PEAR::isError($chan)) {
             return $chan;
         }
@@ -929,7 +948,7 @@ class PEAR_Downloader extends PEAR_Common
         $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;
             }
@@ -954,7 +973,7 @@ class PEAR_Downloader extends PEAR_Common
                 } while (false);
             }
 
-            $chan = &$this->_registry->getChannel($remotechannel);
+            $chan = $this->_registry->getChannel($remotechannel);
             if (PEAR::isError($chan)) {
                 return $chan;
             }
@@ -969,7 +988,7 @@ class PEAR_Downloader extends PEAR_Common
         }
 
         if (isset($dep['uri'])) {
-            $info = &$this->newDownloaderPackage($this);
+            $info = $this->newDownloaderPackage($this);
             PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
             $err = $info->initialize($dep);
             PEAR::staticPopErrorHandling();
@@ -1523,18 +1542,21 @@ class PEAR_Downloader extends PEAR_Common
      *                           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;
@@ -1556,8 +1578,8 @@ class PEAR_Downloader extends PEAR_Common
         $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();
         }
@@ -1639,9 +1661,9 @@ class PEAR_Downloader extends PEAR_Common
         }
 
         $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) {
@@ -1689,7 +1711,7 @@ class PEAR_Downloader extends PEAR_Common
             }
 
             $redirect = $wasredirect + 1;
-            return $this->downloadHttp($headers['location'],
+            return static::_downloadHttp($object, $headers['location'],
                     $ui, $save_dir, $callback, $lastmodified, $accept);
         }
 
@@ -1763,4 +1785,4 @@ class PEAR_Downloader extends PEAR_Common
         }
         return $dest_file;
     }
-}
\ No newline at end of file
+}