📄 package.php
字号:
<?php/** * PEAR_Downloader_Package * * 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> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: Package.php,v 1.1.2.3 2006/05/22 10:19:33 cellog Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 1.4.0a1 *//** * Error code when parameter initialization fails because no releases * exist within preferred_state, but releases do exist */define('PEAR_DOWNLOADER_PACKAGE_STATE', -1003);/** * Coordinates download parameters and manages their dependencies * prior to downloading them. * * Input can come from three sources: * * - local files (archives or package.xml) * - remote files (downloadable urls) * - abstract package names * * The first two elements are handled cleanly by PEAR_PackageFile, but the third requires * accessing pearweb's xml-rpc interface to determine necessary dependencies, and the * format returned of dependencies is slightly different from that used in package.xml. * * This class hides the differences between these elements, and makes automatic * dependency resolution a piece of cake. It also manages conflicts when * two classes depend on incompatible dependencies, or differing versions of the same * package dependency. In addition, download will not be attempted if the php version is * not supported, PEAR installer version is not supported, or non-PECL extensions are not * installed. * @category pear * @package PEAR * @author Greg Beaver <cellog@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @PEAR-VER@ * @link http://pear.php.net/package/PEAR * @since Class available since Release 1.4.0a1 */class PEAR_Downloader_Package{ /** * @var PEAR_Downloader */ var $_downloader; /** * @var PEAR_Config */ var $_config; /** * @var PEAR_Registry */ var $_registry; /** * Used to implement packagingroot properly * @var PEAR_Registry */ var $_installRegistry; /** * @var PEAR_PackageFile_v1|PEAR_PackageFile|v2 */ var $_packagefile; /** * @var array */ var $_parsedname; /** * @var array */ var $_downloadURL; /** * @var array */ var $_downloadDeps = array(); /** * @var boolean */ var $_valid = false; /** * @var boolean */ var $_analyzed = false; /** * if this or a parent package was invoked with Package-state, this is set to the * state variable. * * This allows temporary reassignment of preferred_state for a parent package and all of * its dependencies. * @var string|false */ var $_explicitState = false; /** * If this package is invoked with Package#group, this variable will be true */ var $_explicitGroup = false; /** * Package type local|url|xmlrpc * @var string */ var $_type; /** * Contents of package.xml, if downloaded from a remote channel * @var string|false * @access private */ var $_rawpackagefile; /** * @var boolean * @access private */ var $_validated = false; /** * @param PEAR_Downloader */ function PEAR_Downloader_Package(&$downloader) { $this->_downloader = &$downloader; $this->_config = &$this->_downloader->config; $this->_registry = &$this->_config->getRegistry(); $options = $downloader->getOptions(); if (isset($options['packagingroot'])) { $this->_config->setInstallRoot($options['packagingroot']); $this->_installRegistry = &$this->_config->getRegistry(); $this->_config->setInstallRoot(false); } else { $this->_installRegistry = &$this->_registry; } $this->_valid = $this->_analyzed = false; } /** * Parse the input and determine whether this is a local file, a remote uri, or an * abstract package name. * * This is the heart of the PEAR_Downloader_Package(), and is used in * {@link PEAR_Downloader::download()} * @param string * @return void|PEAR_Error */ function initialize($param) { $origErr = $this->_fromFile($param); if (!$this->_valid) { $options = $this->_downloader->getOptions(); if (isset($options['offline'])) { if (PEAR::isError($origErr)) { if (!isset($options['soft'])) { $this->_downloader->log(0, $origErr->getMessage()); } } return PEAR::raiseError('Cannot download non-local package "' . $param . '"'); } $err = $this->_fromUrl($param); if (PEAR::isError($err) || !$this->_valid) { if ($this->_type == 'url') { if (PEAR::isError($err)) { if (!isset($options['soft'])) { $this->_downloader->log(0, $err->getMessage()); } } return PEAR::raiseError("Invalid or missing remote package file"); } $err = $this->_fromString($param); if (PEAR::isError($err) || !$this->_valid) { if (PEAR::isError($err) && $err->getCode() == PEAR_DOWNLOADER_PACKAGE_STATE) { return false; // instruct the downloader to silently skip } if (isset($this->_type) && $this->_type == 'local' && PEAR::isError($origErr)) { if (is_array($origErr->getUserInfo())) { foreach ($origErr->getUserInfo() as $err) { if (is_array($err)) { $err = $err['message']; } if (!isset($options['soft'])) { $this->_downloader->log(0, $err); } } } if (!isset($options['soft'])) { $this->_downloader->log(0, $origErr->getMessage()); } if (is_array($param)) { $param = $this->_registry->parsedPackageNameToString($param, true); } return PEAR::raiseError( "Cannot initialize '$param', invalid or missing package file"); } if (PEAR::isError($err)) { if (!isset($options['soft'])) { $this->_downloader->log(0, $err->getMessage()); } } if (is_array($param)) { $param = $this->_registry->parsedPackageNameToString($param, true); } return PEAR::raiseError( "Cannot initialize '$param', invalid or missing package file"); } } } return true; } /** * Retrieve any non-local packages * @return PEAR_PackageFile_v1|PEAR_PackageFile_v2|PEAR_Error */ function &download() { if (isset($this->_packagefile)) { return $this->_packagefile; } if (isset($this->_downloadURL['url'])) { $this->_isvalid = false; $info = $this->getParsedPackage(); foreach ($info as $i => $p) { $info[$i] = strtolower($p); } $err = $this->_fromUrl($this->_downloadURL['url'], $this->_registry->parsedPackageNameToString($this->_parsedname, true)); $newinfo = $this->getParsedPackage(); foreach ($newinfo as $i => $p) { $newinfo[$i] = strtolower($p); } if ($info != $newinfo) { do { if ($info['package'] == 'pecl.php.net' && $newinfo['package'] == 'pear.php.net') { $info['package'] = 'pear.php.net'; if ($info == $newinfo) { // skip the channel check if a pecl package says it's a PEAR package break; } } return PEAR::raiseError('CRITICAL ERROR: We are ' . $this->_registry->parsedPackageNameToString($info) . ', but the file ' . 'downloaded claims to be ' . $this->_registry->parsedPackageNameToString($this->getParsedPackage())); } while (false); } if (PEAR::isError($err) || !$this->_valid) { return $err; } } $this->_type = 'local'; return $this->_packagefile; } function &getPackageFile() { return $this->_packagefile; } function &getDownloader() { return $this->_downloader; } function getType() { return $this->_type; } /** * Like {@link initialize()}, but operates on a dependency */ function fromDepURL($dep) { $this->_downloadURL = $dep; if (isset($dep['uri'])) { $options = $this->_downloader->getOptions(); if (!extension_loaded("zlib") || isset($options['nocompress'])) { $ext = '.tar'; } else { $ext = '.tgz'; } PEAR::pushErrorHandling(PEAR_ERROR_RETURN); $err = $this->_fromUrl($dep['uri'] . $ext); PEAR::popErrorHandling(); if (PEAR::isError($err)) { if (!isset($options['soft'])) { $this->_downloader->log(0, $err->getMessage()); } return PEAR::raiseError('Invalid uri dependency "' . $dep['uri'] . $ext . '", ' . 'cannot download'); } } else { $this->_parsedname = array( 'package' => $dep['info']->getPackage(), 'channel' => $dep['info']->getChannel(), 'version' => $dep['version'] ); if (!isset($dep['nodefault'])) { $this->_parsedname['group'] = 'default'; // download the default dependency group $this->_explicitGroup = false; } $this->_rawpackagefile = $dep['raw']; } } function detectDependencies($params) { $options = $this->_downloader->getOptions(); if (isset($options['downloadonly'])) { return; } if (isset($options['offline'])) { $this->_downloader->log(3, 'Skipping dependency download check, --offline specified');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -