📄 downloader.php
字号:
<?php/** * PEAR_Downloader, the PEAR Installer's download utility class * * PHP versions 4 and 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category pear * @package PEAR * @author Greg Beaver <cellog@php.net> * @author Stig Bakken <ssb@php.net> * @author Tomas V. V. Cox <cox@idecnet.com> * @author Martin Jansen <mj@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: Downloader.php,v 1.9.2.8.2.3 2006/05/22 11:17:01 cellog Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 1.3.0 *//** * Needed for constants, extending */require_once 'PEAR/Common.php';define('PEAR_INSTALLER_OK', 1);define('PEAR_INSTALLER_FAILED', 0);define('PEAR_INSTALLER_SKIPPED', -1);define('PEAR_INSTALLER_ERROR_NO_PREF_STATE', 2);/** * Administration class used to download anything from the internet (PEAR Packages, * static URLs, xml files) * * @category pear * @package PEAR * @author Greg Beaver <cellog@php.net> * @author Stig Bakken <ssb@php.net> * @author Tomas V. V. Cox <cox@idecnet.com> * @author Martin Jansen <mj@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PEAR * @since Class available since Release 1.3.0 */class PEAR_Downloader extends PEAR_Common{ /** * @var PEAR_Registry * @access private */ var $_registry; /** * @var PEAR_Remote * @access private */ var $_remote; /** * Preferred Installation State (snapshot, devel, alpha, beta, stable) * @var string|null * @access private */ var $_preferredState; /** * Options from command-line passed to Install. * * Recognized options:<br /> * - onlyreqdeps : install all required dependencies as well * - alldeps : install all dependencies, including optional * - installroot : base relative path to install files in * - force : force a download even if warnings would prevent it * - nocompress : download uncompressed tarballs * @see PEAR_Command_Install * @access private * @var array */ var $_options; /** * Downloaded Packages after a call to download(). * * Format of each entry: * * <code> * array('pkg' => 'package_name', 'file' => '/path/to/local/file', * 'info' => array() // parsed package.xml * ); * </code> * @access private * @var array */ var $_downloadedPackages = array(); /** * Packages slated for download. * * This is used to prevent downloading a package more than once should it be a dependency * for two packages to be installed. * Format of each entry: * * <pre> * array('package_name1' => parsed package.xml, 'package_name2' => parsed package.xml, * ); * </pre> * @access private * @var array */ var $_toDownload = array(); /** * Array of every package installed, with names lower-cased. * * Format: * <code> * array('package1' => 0, 'package2' => 1, ); * </code> * @var array */ var $_installed = array(); /** * @var array * @access private */ var $_errorStack = array(); /** * @var boolean * @access private */ var $_internalDownload = false; /** * Temporary variable used in sorting packages by dependency in {@link sortPkgDeps()} * @var array * @access private */ var $_packageSortTree; /** * Temporary directory, or configuration value where downloads will occur * @var string */ var $_downloadDir; // {{{ PEAR_Downloader() /** * @param PEAR_Frontend_* * @param array * @param PEAR_Config */ function PEAR_Downloader(&$ui, $options, &$config) { parent::PEAR_Common(); $this->_options = $options; $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']); } $this->_registry = &$config->getRegistry(); $this->_remote = &$config->getRemote(); if (isset($this->_options['alldeps']) || isset($this->_options['onlyreqdeps'])) { $this->_installed = $this->_registry->listAllPackages(); foreach ($this->_installed as $key => $unused) { if (!count($unused)) { continue; } @array_walk($this->_installed[$key], 'strtolower'); } } } /** * Attempt to discover a channel's remote capabilities from * its server name * @param string * @return boolean */ function discover($channel) { $this->log(1, 'Attempting to discover channel "' . $channel . '"...'); PEAR::pushErrorHandling(PEAR_ERROR_RETURN); $callback = $this->ui ? array(&$this, '_downloadCallback') : null; if (!class_exists('System')) { require_once 'System.php'; } $a = $this->downloadHttp('http://' . $channel . '/channel.xml', $this->ui, System::mktemp(array('-d')), $callback, false); PEAR::popErrorHandling(); if (PEAR::isError($a)) { return false; } list($a, $lastmodified) = $a; if (!class_exists('PEAR/ChannelFile.php')) { require_once 'PEAR/ChannelFile.php'; } $b = new PEAR_ChannelFile; if ($b->fromXmlFile($a)) { @unlink($a); if ($this->config->get('auto_discover')) { $this->_registry->addChannel($b, $lastmodified); $alias = $b->getName(); if ($b->getName() == $this->_registry->channelName($b->getAlias())) { $alias = $b->getAlias(); } $this->log(1, 'Auto-discovered channel "' . $channel . '", alias "' . $alias . '", adding to registry'); } return true; } @unlink($a); return false; } /** * For simpler unit-testing * @param PEAR_Downloader * @return PEAR_Downloader_Package */ function &newDownloaderPackage(&$t) { if (!class_exists('PEAR_Downloader_Package')) { require_once 'PEAR/Downloader/Package.php'; } $a = &new PEAR_Downloader_Package($t); return $a; } /** * For simpler unit-testing * @param PEAR_Config * @param array * @param array * @param int */ function &getDependency2Object(&$c, $i, $p, $s) { if (!class_exists('PEAR/Dependency2.php')) { require_once 'PEAR/Dependency2.php'; } $z = &new PEAR_Dependency2($c, $i, $p, $s); return $z; } function &download($params) { if (!count($params)) { $a = array(); return $a; } if (!isset($this->_registry)) { $this->_registry = &$this->config->getRegistry(); } if (!isset($this->_remote)) { $this->_remote = &$this->config->getRemote(); } $channelschecked = array(); // convert all parameters into PEAR_Downloader_Package objects foreach ($params as $i => $param) { $params[$i] = &$this->newDownloaderPackage($this); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $err = $params[$i]->initialize($param); PEAR::staticPopErrorHandling(); if (!$err) { // skip parameters that were missed by preferred_state continue; } if (PEAR::isError($err)) { if (!isset($this->_options['soft'])) { $this->log(0, $err->getMessage()); } $params[$i] = false; if (is_object($param)) { $param = $param->getChannel() . '/' . $param->getPackage(); } $this->pushError('Package "' . $param . '" is not valid', PEAR_INSTALLER_SKIPPED); } else { if ($params[$i] && !isset($channelschecked[$params[$i]->getChannel()]) && !isset($this->_options['offline'])) { $channelschecked[$params[$i]->getChannel()] = true; PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); if (!class_exists('System')) { require_once 'System.php'; } $curchannel = &$this->_registry->getChannel($params[$i]->getChannel()); if (PEAR::isError($curchannel)) { PEAR::staticPopErrorHandling(); return $this->raiseError($curchannel); } $a = $this->downloadHttp('http://' . $params[$i]->getChannel() . '/channel.xml', $this->ui, System::mktemp(array('-d')), null, $curchannel->lastModified()); PEAR::staticPopErrorHandling(); if (PEAR::isError($a) || !$a) { continue; } $this->log(0, 'WARNING: channel "' . $params[$i]->getChannel() . '" has ' . 'updated its protocols, use "channel-update ' . $params[$i]->getChannel() . '" to update'); } if ($params[$i] && !isset($this->_options['downloadonly'])) { if (isset($this->_options['packagingroot'])) { $checkdir = $this->_prependPath( $this->config->get('php_dir', null, $params[$i]->getChannel()), $this->_options['packagingroot']); } else { $checkdir = $this->config->get('php_dir', null, $params[$i]->getChannel()); } while ($checkdir && $checkdir != '/' && !file_exists($checkdir)) { $checkdir = dirname($checkdir); } if ($checkdir == '.') { $checkdir = '/'; } if (!@is_writeable($checkdir)) { return PEAR::raiseError('Cannot install, php_dir for channel "' . $params[$i]->getChannel() . '" is not writeable by the current user'); } } } } unset($channelschecked); PEAR_Downloader_Package::removeDuplicates($params); if (!count($params)) { $a = array(); return $a; } if (!isset($this->_options['nodeps']) && !isset($this->_options['offline'])) { $reverify = true; while ($reverify) { $reverify = false; foreach ($params as $i => $param) { $ret = $params[$i]->detectDependencies($params); if (PEAR::isError($ret)) { $reverify = true; $params[$i] = false; PEAR_Downloader_Package::removeDuplicates($params); if (!isset($this->_options['soft'])) { $this->log(0, $ret->getMessage()); } continue 2; } } } } if (isset($this->_options['offline'])) { $this->log(3, 'Skipping dependency download check, --offline specified'); } if (!count($params)) { $a = array(); return $a; } while (PEAR_Downloader_Package::mergeDependencies($params)); PEAR_Downloader_Package::removeInstalled($params); if (!count($params)) { $this->pushError('No valid packages found', PEAR_INSTALLER_FAILED); $a = array(); return $a; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -