📄 downloader.php
字号:
$pf = new PEAR_PackageFile_v2; $pf->setRawChannel($parr['channel']); if ($url['compatible']) { $pf->setRawCompatible($url['compatible']); } } else { require_once 'PEAR/PackageFile/v1.php'; $pf = new PEAR_PackageFile_v1; } $pf->setRawPackage($url['package']); $pf->setDeps($url['info']); $pf->setRawState($url['stability']); $url['info'] = &$pf; if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) { $ext = '.tar'; } else { $ext = '.tgz'; } if (is_array($url)) { if (isset($url['url'])) { $url['url'] .= $ext; } } return $url; } elseif ($chan->supports('xmlrpc', 'package.getDownloadURL', false, '1.1')) { // don't install with the old version information unless we're doing a plain // vanilla simple installation. If the user says to install a particular // version or state, ignore the current installed version if (!isset($parr['version']) && !isset($parr['state']) && $version && !isset($this->_options['downloadonly'])) { $url = $this->_remote->call('package.getDownloadURL', $parr, $state, $version); } else { $url = $this->_remote->call('package.getDownloadURL', $parr, $state); } } else { $url = $this->_remote->call('package.getDownloadURL', $parr, $state); } if (PEAR::isError($url)) { return $url; } if ($parr['channel'] != $curchannel) { $this->configSet('default_channel', $curchannel); } if (isset($url['__PEAR_ERROR_CLASS__'])) { return PEAR::raiseError($url['message']); } if (!is_array($url)) { return $url; } $url['raw'] = $url['info']; if (isset($this->_options['downloadonly'])) { $pkg = &$this->getPackagefileObject($this->config, $this->debug); } else { $pkg = &$this->getPackagefileObject($this->config, $this->debug, $this->getDownloadDir()); } PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $pinfo = &$pkg->fromXmlString($url['info'], PEAR_VALIDATE_DOWNLOADING, 'remote'); PEAR::staticPopErrorHandling(); if (PEAR::isError($pinfo)) { if (!isset($this->_options['soft'])) { $this->log(0, $pinfo->getMessage()); } return PEAR::raiseError('Remote package.xml is not valid - this should never happen'); } $url['info'] = &$pinfo; if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) { $ext = '.tar'; } else { $ext = '.tgz'; } if (is_array($url)) { if (isset($url['url'])) { $url['url'] .= $ext; } } return $url; } // }}} // {{{ getDepPackageDownloadUrl() /** * @param array dependency array * @access private */ function _getDepPackageDownloadUrl($dep, $parr) { $xsdversion = isset($dep['rel']) ? '1.0' : '2.0'; $curchannel = $this->config->get('default_channel'); if (isset($dep['channel'])) { $remotechannel = $dep['channel']; } else { $remotechannel = 'pear.php.net'; } if (!$this->_registry->channelExists($remotechannel)) { do { if ($this->config->get('auto_discover')) { if ($this->discover($remotechannel)) { break; } } return PEAR::raiseError('Unknown remote channel: ' . $remotechannel); } while (false); } $this->configSet('default_channel', $remotechannel); $state = isset($parr['state']) ? $parr['state'] : $this->config->get('preferred_state'); if (isset($parr['state']) && isset($parr['version'])) { unset($parr['state']); } $chan = &$this->_registry->getChannel($remotechannel); if (PEAR::isError($chan)) { return $chan; } $version = $this->_registry->packageInfo($dep['name'], 'version', $remotechannel); if ($chan->supportsREST($this->config->get('preferred_mirror')) && $base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) { $rest = &$this->config->getREST('1.0', $this->_options); $url = $rest->getDepDownloadURL($base, $xsdversion, $dep, $parr, $state, $version); if (PEAR::isError($url)) { return $url; } if ($parr['channel'] != $curchannel) { $this->configSet('default_channel', $curchannel); } if (!is_array($url)) { return $url; } $url['raw'] = false; // no checking is necessary for REST if (!is_array($url['info'])) { return PEAR::raiseError('Invalid remote dependencies retrieved from REST - ' . 'this should never happen'); } if (isset($url['info']['required'])) { if (!class_exists('PEAR_PackageFile_v2')) { require_once 'PEAR/PackageFile/v2.php'; } $pf = new PEAR_PackageFile_v2; $pf->setRawChannel($remotechannel); } else { if (!class_exists('PEAR_PackageFile_v1')) { require_once 'PEAR/PackageFile/v1.php'; } $pf = new PEAR_PackageFile_v1; } $pf->setRawPackage($url['package']); $pf->setDeps($url['info']); $pf->setRawState($url['stability']); $url['info'] = &$pf; if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) { $ext = '.tar'; } else { $ext = '.tgz'; } if (is_array($url)) { if (isset($url['url'])) { $url['url'] .= $ext; } } return $url; } elseif ($chan->supports('xmlrpc', 'package.getDepDownloadURL', false, '1.1')) { if ($version) { $url = $this->_remote->call('package.getDepDownloadURL', $xsdversion, $dep, $parr, $state, $version); } else { $url = $this->_remote->call('package.getDepDownloadURL', $xsdversion, $dep, $parr, $state); } } else { $url = $this->_remote->call('package.getDepDownloadURL', $xsdversion, $dep, $parr, $state); } if ($parr['channel'] != $curchannel) { $this->configSet('default_channel', $curchannel); } if (!is_array($url)) { return $url; } if (isset($url['__PEAR_ERROR_CLASS__'])) { return PEAR::raiseError($url['message']); } $url['raw'] = $url['info']; $pkg = &$this->getPackagefileObject($this->config, $this->debug); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $pinfo = &$pkg->fromXmlString($url['info'], PEAR_VALIDATE_DOWNLOADING, 'remote'); PEAR::staticPopErrorHandling(); if (PEAR::isError($pinfo)) { if (!isset($this->_options['soft'])) { $this->log(0, $pinfo->getMessage()); } return PEAR::raiseError('Remote package.xml is not valid - this should never happen'); } $url['info'] = &$pinfo; if (is_array($url)) { if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) { $ext = '.tar'; } else { $ext = '.tgz'; } if (isset($url['url'])) { $url['url'] .= $ext; } } return $url; } // }}} // {{{ getPackageDownloadUrl() /** * @deprecated in favor of _getPackageDownloadUrl */ function getPackageDownloadUrl($package, $version = null, $channel = false) { if ($version) { $package .= "-$version"; } if ($this === null || $this->_registry === null) { $package = "http://pear.php.net/get/$package"; } else { $chan = $this->_registry->getChannel($channel); if (PEAR::isError($chan)) { return ''; } $package = "http://" . $chan->getServer() . "/get/$package"; } if (!extension_loaded("zlib")) { $package .= '?uncompress=yes'; } return $package; } // }}} // {{{ getDownloadedPackages() /** * Retrieve a list of downloaded packages after a call to {@link download()}. * * Also resets the list of downloaded packages. * @return array */ function getDownloadedPackages() { $ret = $this->_downloadedPackages; $this->_downloadedPackages = array(); $this->_toDownload = array(); return $ret; } // }}} // {{{ _downloadCallback() function _downloadCallback($msg, $params = null) { switch ($msg) { case 'saveas': $this->log(1, "downloading $params ..."); break; case 'done': $this->log(1, '...done: ' . number_format($params, 0, '', ',') . ' bytes'); break; case 'bytesread': static $bytes; if (empty($bytes)) { $bytes = 0; } if (!($bytes % 10240)) { $this->log(1, '.', false); } $bytes += $params; break; case 'start': $this->log(1, "Starting to download {$params[0]} (".number_format($params[1], 0, '', ',')." bytes)"); break; } if (method_exists($this->ui, '_downloadCallback')) $this->ui->_downloadCallback($msg, $params); } // }}} // {{{ _prependPath($path, $prepend) function _prependPath($path, $prepend) { if (strlen($prepend) > 0) { if (OS_WINDOWS && preg_match('/^[a-z]:/i', $path)) { if (preg_match('/^[a-z]:/i', $prepend)) { $prepend = substr($prepend, 2); } elseif ($prepend{0} != '\\') { $prepend = "\\$prepend"; } $path = substr($path, 0, 2) . $prepend . substr($path, 2); } else { $path = $prepend . $path; } } return $path; } // }}} // {{{ pushError($errmsg, $code) /** * @param string * @param integer */ function pushError($errmsg, $code = -1) { array_push($this->_errorStack, array($errmsg, $code)); } // }}} // {{{ getErrorMsgs() function getErrorMsgs() { $msgs = array(); $errs = $this->_errorStack; foreach ($errs as $err) { $msgs[] = $err[0]; } $this->_errorStack = array(); return $msgs; } // }}} /** * for BC */ function sortPkgDeps(&$packages, $uninstall = false) { $uninstall ? $this->sortPackagesForUninstall($packages) : $this->sortPackagesForInstall($packages); } function _getDepTreeDP($package, $packages, &$deps, &$checked) { $pf = $package->getPackageFile(); $checked[strtolower($package->getChannel())][strtolower($package->getPackage())] = true; $pdeps = $pf->getDeps(true); if (!$pdeps) { return; } if ($pf->getPackagexmlVersion() == '1.0') { foreach ($pdeps as $dep) { if ($dep['type'] != 'pkg') { continue; } $deps['pear.php.net'][strtolower($dep['name'])] = true; foreach ($packages as $p) { $dep['channel'] = 'pear.php.net'; $dep['package'] = $dep['name']; if ($p->isEqual($dep)) { if (!isset($checked[strtolower($p->getChannel())] [strtolower($p->getPackage())])) { // add the dependency's dependencies to the tree $this->_getDepTreeDP($p, $packages, $deps, $checked); } } } } } else { $tdeps = array(); if (isset($pdeps['required']['package'])) { $t = $pdeps['required']['package']; if (!isset($t[0])) { $t = array($t); } $tdeps = array_merge($tdeps, $t); } if (isset($pdeps['required']['subpackage'])) { $t = $pdeps['required']['subpackage']; if (!isset($t[0])) { $t = array($t); } $tdeps = array_merge($tdeps, $t); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -