📄 install.php
字号:
// }}} // {{{ constructor /** * PEAR_Command_Install constructor. * * @access public */ function PEAR_Command_Install(&$ui, &$config) { parent::PEAR_Command_Common($ui, $config); } // }}} // {{{ doInstall() function doInstall($command, $options, $params) { require_once 'PEAR/Downloader.php'; if (empty($this->installer)) { $this->installer = &new PEAR_Installer($this->ui); } if ($command == 'upgrade') { $options['upgrade'] = true; } if ($command == 'upgrade-all') { include_once "PEAR/Remote.php"; $options['upgrade'] = true; $remote = &new PEAR_Remote($this->config); $state = $this->config->get('preferred_state'); if (empty($state) || $state == 'any') { $latest = $remote->call("package.listLatestReleases"); } else { $latest = $remote->call("package.listLatestReleases", $state); } if (PEAR::isError($latest)) { return $latest; } $reg = new PEAR_Registry($this->config->get('php_dir')); $installed = array_flip($reg->listPackages()); $params = array(); foreach ($latest as $package => $info) { $package = strtolower($package); if (!isset($installed[$package])) { // skip packages we don't have installed continue; } $inst_version = $reg->packageInfo($package, 'version'); if (version_compare("$info[version]", "$inst_version", "le")) { // installed version is up-to-date continue; } $params[] = $package; $this->ui->outputData(array('data' => "Will upgrade $package"), $command); } } $this->downloader = &new PEAR_Downloader($this->ui, $options, $this->config); $errors = array(); $downloaded = array(); $this->downloader->download($params); $errors = $this->downloader->getErrorMsgs(); if (count($errors)) { $err['data'] = array($errors); $err['headline'] = 'Install Errors'; $this->ui->outputData($err); return $this->raiseError("$command failed"); } $downloaded = $this->downloader->getDownloadedPackages(); $this->installer->sortPkgDeps($downloaded); foreach ($downloaded as $pkg) { $bn = basename($pkg['file']); $info = $this->installer->install($pkg['file'], $options, $this->config); if (is_array($info)) { if ($this->config->get('verbose') > 0) { $label = "$info[package] $info[version]"; $out = array('data' => "$command ok: $label"); if (isset($info['release_warnings'])) { $out['release_warnings'] = $info['release_warnings']; } $this->ui->outputData($out, $command); } } else { return $this->raiseError("$command failed"); } } return true; } // }}} // {{{ doUninstall() function doUninstall($command, $options, $params) { if (empty($this->installer)) { $this->installer = &new PEAR_Installer($this->ui); } if (sizeof($params) < 1) { return $this->raiseError("Please supply the package(s) you want to uninstall"); } include_once 'PEAR/Registry.php'; $reg = new PEAR_Registry($this->config->get('php_dir')); $newparams = array(); $badparams = array(); foreach ($params as $pkg) { $info = $reg->packageInfo($pkg); if ($info === null) { $badparams[] = $pkg; } else { $newparams[] = $info; } } $this->installer->sortPkgDeps($newparams, true); $params = array(); foreach($newparams as $info) { $params[] = $info['info']['package']; } $params = array_merge($params, $badparams); foreach ($params as $pkg) { if ($this->installer->uninstall($pkg, $options)) { if ($this->config->get('verbose') > 0) { $this->ui->outputData("uninstall ok: $pkg", $command); } } else { return $this->raiseError("uninstall failed: $pkg"); } } return true; } // }}} // }}} // {{{ doBundle() /* (cox) It just downloads and untars the package, does not do any check that the PEAR_Installer::_installFile() does. */ function doBundle($command, $options, $params) { if (empty($this->installer)) { $this->installer = &new PEAR_Downloader($this->ui); } $installer = &$this->installer; if (sizeof($params) < 1) { return $this->raiseError("Please supply the package you want to bundle"); } $pkgfile = $params[0]; $need_download = false; if (preg_match('#^(http|ftp)://#', $pkgfile)) { $need_download = true; } elseif (!@is_file($pkgfile)) { if ($installer->validPackageName($pkgfile)) { $pkgfile = $installer->getPackageDownloadUrl($pkgfile); $need_download = true; } else { if (strlen($pkgfile)) { return $this->raiseError("Could not open the package file: $pkgfile"); } else { return $this->raiseError("No package file given"); } } } // Download package ----------------------------------------------- if ($need_download) { $downloaddir = $installer->config->get('download_dir'); if (empty($downloaddir)) { if (PEAR::isError($downloaddir = System::mktemp('-d'))) { return $downloaddir; } $installer->log(2, '+ tmp dir created at ' . $downloaddir); } $callback = $this->ui ? array(&$installer, '_downloadCallback') : null; $file = $installer->downloadHttp($pkgfile, $this->ui, $downloaddir, $callback); if (PEAR::isError($file)) { return $this->raiseError($file); } $pkgfile = $file; } // Parse xml file ----------------------------------------------- $pkginfo = $installer->infoFromTgzFile($pkgfile); if (PEAR::isError($pkginfo)) { return $this->raiseError($pkginfo); } $installer->validatePackageInfo($pkginfo, $errors, $warnings); // XXX We allow warnings, do we have to do it? if (count($errors)) { if (empty($options['force'])) { return $this->raiseError("The following errors where found:\n". implode("\n", $errors)); } else { $this->log(0, "warning : the following errors were found:\n". implode("\n", $errors)); } } $pkgname = $pkginfo['package']; // Unpacking ------------------------------------------------- if (isset($options['destination'])) { if (!is_dir($options['destination'])) { System::mkdir('-p ' . $options['destination']); } $dest = realpath($options['destination']); } else { $pwd = getcwd(); if (is_dir($pwd . DIRECTORY_SEPARATOR . 'ext')) { $dest = $pwd . DIRECTORY_SEPARATOR . 'ext'; } else { $dest = $pwd; } } $dest .= DIRECTORY_SEPARATOR . $pkgname; $orig = $pkgname . '-' . $pkginfo['version']; $tar = new Archive_Tar($pkgfile); if (!@$tar->extractModify($dest, $orig)) { return $this->raiseError("unable to unpack $pkgfile"); } $this->ui->outputData("Package ready at '$dest'"); // }}} } // }}}}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -