/** * retrieves a list of avaible Packages from master server * and downloads them * * @access public * @param string $command the command * @param array $options the command options before the command * @param array $params the stuff after the command name * @return bool true if succesful * @throw PEAR_Error */ function doDownloadAll($command, $options, $params) { $this->config->set("php_dir", "."); $remote =& new PEAR_Remote($this->config); $remoteInfo = $remote->call("package.listAll"); if (PEAR::isError($remoteInfo)) { return $remoteInfo; } $cmd =& PEAR_Command::factory("download", $this->config); if (PEAR::isError($cmd)) { return $cmd; } foreach ($remoteInfo as $pkgn => $pkg) { // error handling not neccesary, because // already done by the download command $cmd->run("download", array(), array($pkgn)); } return true; }
/** * do the install * * @access public * @param string $command the command * @param array $options the command options before the command * @param array $params the stuff after the command name * @return bool true if succesful * @throw PEAR_Error */ function doInstallAll($command, $options, $params) { $remote =& new PEAR_Remote($this->config); $remoteInfo = $remote->call("package.listAll"); if (PEAR::isError($remoteInfo)) { return $remoteInfo; } $cmd =& PEAR_Command::factory("install", $this->config); if (PEAR::isError($cmd)) { return $cmd; } foreach ($remoteInfo as $pkgn => $pkg) { // error handling not neccesary, because // already done by the install command $options = array("nodeps" => true, "force" => true, "nobuild" => $options['nobuild']); $cmd->run("install", $options, array($pkgn)); } return true; }
function PEAR_Start_CLI() { parent::PEAR_Start(); ini_set('html_errors', 0); define('WIN32GUI', OS_WINDOWS && php_sapi_name() == 'cli' && System::which('cscript')); $this->tty = OS_WINDOWS ? @fopen('\\con', 'r') : @fopen('/dev/tty', 'r'); if (!$this->tty) { $this->tty = fopen('php://stdin', 'r'); } $this->origpwd = getcwd(); $this->config = array_keys($this->configPrompt); // make indices run from 1... array_unshift($this->config, ""); unset($this->config[0]); reset($this->config); $this->descLength = max(array_map('strlen', $this->configPrompt)); $this->descFormat = "%-{$this->descLength}s"; $this->first = key($this->config); end($this->config); $this->last = key($this->config); PEAR_Command::setFrontendType('CLI'); }
public function invoke() { $params = func_get_args(); switch (func_num_args()) { case 1: list($command) = $params; $options = array(); $args = array(); break; case 2: list($command, $options) = $params; if (is_string($options)) { $args = array($options); $options = array(); } else { $args = array(); } break; case 3: list($command, $options, $args) = $params; if (is_string($args)) { if (is_string($options)) { $args = array($options, $args); $options = array(); } else { $args = array($args); } } break; default: $command = array_shift($params); if (is_array($params[0])) { $options = array_shift($params); } $args = $params; } $cmd = \PEAR_Command::factory($command, $this->config); $cmd->run($command, $options, $args); }
public function run($command, $options = array(), $params = array()) { @set_time_limit(0); @ini_set('memory_limit', '256M'); if (empty($this->_cmdCache[$command])) { $cmd = PEAR_Command::factory($command, $this->getConfig()); if ($cmd instanceof PEAR_Error) { return $cmd; } $this->_cmdCache[$command] = $cmd; } else { $cmd = $this->_cmdCache[$command]; } #$cmd = PEAR_Command::factory($command, $this->getConfig()); $result = $cmd->run($command, $options, $params); return $result; }
/** * Get help for command. * * @param string $command Name of the command to return help for * * @access public * @static */ function getHelp($command) { $cmds = PEAR_Command::getCommands(); if (isset($cmds[$command])) { $class = $cmds[$command]; return $GLOBALS['_PEAR_Command_objects'][$class]->getHelp($command); } return false; }
/** * Initializes the * @param unknown_type $command * @param array $opts * @param array $params * @return unknown_type */ protected function _command($command, array $opts = array(), array $params = array()) { // initialize the command $cmd = PEAR_Command::factory($command, $this->_config); if (PEAR::isError($cmd)) { throw new Exception($cmd->getMessage()); } // run the command return $cmd->run($command, $opts, $params); }
$command = 'config-set'; $params = array($var, $value); $cmd = PEAR_Command::factory($command, $config); $res = $cmd->run($command, $opts, $params); } $URL .= '?command=config-show'; Header("Location: " . $URL); exit; case 'list-all': $command = $_GET["command"]; $params = array(); if (isset($_GET["mode"])) { $opts['mode'] = $_GET["mode"]; } $cmd = PEAR_Command::factory($command, $config); $ok = $cmd->run($command, $opts, $params); exit; case 'show-last-error': $GLOBALS['_PEAR_Frontend_Web_log'] = $_SESSION['_PEAR_Frontend_Web_LastError_log']; $ui->displayError($_SESSION['_PEAR_Frontend_Web_LastError'], 'Error', 'error', true); exit; default: $command = $_GET["command"]; $cmd = PEAR_Command::factory($command, $config); $res = $cmd->run($command, $opts, $params); $URL .= '?command=' . $_GET["command"]; Header("Location: " . $URL); exit; } } $ui->displayStart();
private static function nativePearUpgrade($package, $channel) { pake_echo_action('pear', 'upgrading ' . $channel . '/' . $package); self::initPearClasses(); $front = PEAR_Frontend::singleton('PEAR_Frontend_CLI'); $cfg = PEAR_Config::singleton(); $cmd = PEAR_Command::factory('upgrade', $cfg); ob_start(); $result = $cmd->doInstall('upgrade', array(), array($channel . '/' . $package)); ob_end_clean(); // we don't need output if ($result instanceof PEAR_Error) { throw new pakeException($result->getMessage()); } }
/** * For unit-testing */ function &factory($a) { $a =& PEAR_Command::factory($a, $this->config); return $a; }
function doInstall() { print "Beginning install...\n"; // finish php_bin config if (OS_WINDOWS) { $this->php_bin .= '\\php.exe'; } else { $this->php_bin .= '/php'; } $this->PEARConfig =& PEAR_Config::singleton($this->pear_conf, $this->pear_conf); $this->PEARConfig->set('preferred_state', 'stable'); foreach ($this->config as $var) { if ($var == 'pear_conf' || $var == 'prefix') { continue; } $this->PEARConfig->set($var, $this->{$var}); } $this->PEARConfig->store(); // $this->PEARConfig->set('verbose', 6); print "Configuration written to {$this->pear_conf}...\n"; $this->registry =& $this->PEARConfig->getRegistry(); print "Initialized registry...\n"; $install =& PEAR_Command::factory('install', $this->PEARConfig); print "Preparing to install...\n"; $options = array('nodeps' => true, 'force' => true, 'upgrade' => true); foreach ($this->tarball as $pkg => $src) { print "installing {$src}...\n"; } $install->run('install', $options, array_values($this->tarball)); }
private function nativePearInstall($package, $channel) { if (!class_exists('PEAR_Command')) { @(include 'PEAR/command.php'); // loads frontend, among other things if (!class_exists('PEAR_Command')) { throw new pakeException('PEAR subsystem is unavailable (not in include_path?)'); } } $front = PEAR_Frontend::singleton('PEAR_Frontend_CLI'); $cfg = PEAR_Config::singleton(); $cmd = PEAR_Command::factory('install', $cfg); ob_start(); $result = $cmd->doInstall('install', array(), array($channel . '/' . $package)); ob_end_clean(); // we don't need output if ($result instanceof PEAR_Error) { throw new pakeException($result->getMessage()); } }
/** * @access private */ function &_makePackage($setting, $workdir) { // package.xml を作る $pkgconfig = array('packagedirectory' => $workdir, 'outputdirectory' => $workdir, 'ignore' => array('CVS/', '.cvsignore', '.svn/', 'package.xml', '*.ini', $setting['pkgname'] . '-*.tgz'), 'filelistgenerator' => 'file', 'changelogoldtonew' => false); $packagexml = new PEAR_PackageFileManager2(); $pkgconfig = array_merge($pkgconfig, $setting['config']); $packagexml->setOptions($pkgconfig); $packagexml->setPackage($setting['pkgname']); $packagexml->setSummary($setting['summary']); $packagexml->setNotes($setting['notes']); $packagexml->setDescription($setting['description']); $packagexml->setChannel($setting['channel']); $packagexml->setAPIVersion($setting['version']); $packagexml->setReleaseVersion($setting['version']); $packagexml->setReleaseStability($setting['state']); $packagexml->setAPIStability($setting['state']); $packagexml->setPackageType('php'); foreach ($setting['maintainers'] as $m) { $packagexml->addMaintainer($m['role'], $m['user'], $m['name'], $m['email'], $m['active']); } $packagexml->setLicense($setting['license']['name'], $setting['license']['uri']); $packagexml->addRole('css', 'php'); $packagexml->addRole('tpl', 'php'); $packagexml->addRole('ethna', 'php'); $packagexml->addRole('sh', 'script'); $packagexml->addRole('bat', 'script'); $packagexml->setPhpDep('4.3.0'); $packagexml->setPearinstallerDep('1.3.5'); $packagexml->generateContents(); foreach ($setting['callback'] as $method => $params) { $r = call_user_func_array(array(&$packagexml, $method), $params); } $r = $packagexml->writePackageFile(); if (PEAR::isError($r)) { return Ethna::raiseError($r->getMessage, $r->getCode()); } // finally make package PEAR_Command::setFrontendType('CLI'); $ui = PEAR_Command::getFrontendObject(); $config = PEAR_Config::singleton(); $ui->setConfig($config); PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array(&$ui, 'displayFatalError')); $cmd = PEAR_Command::factory('package', $config); if (PEAR::isError($cmd)) { return Ethna::raiseError($cmd->getMessage, $cmd->getCode()); } $r = $cmd->run('package', array(), array("{$workdir}/package.xml")); if (PEAR::isError($r)) { return Ethna::raiseError($r->getMessage, $r->getCode()); } }
} $config->set('download_dir', $temp_dir . '/download'); $config->set('temp_dir', $temp_dir); $config->store(); $registry = new PEAR_Registry($php_dir); PEAR_Command::setFrontendType('CLI'); PEAR::staticPushErrorHandling(PEAR_ERROR_DIE); //fail silently $ch_cmd =& PEAR_Command::factory('update-channels', $config); $ch_cmd->run('update-channels', $options, array()); PEAR::staticPopErrorHandling(); // reset error handling unset($ch_cmd); print "\n" . 'Installing selected packages..................' . "\n"; displayHTMLProgress($progress = 45); $install =& PEAR_Command::factory('install', $config); foreach ($to_install as $pkg) { $pkg_basename = substr($pkg, 0, strpos($pkg, '-')); if (in_array($pkg, $installer_packages)) { $options = array('nodeps' => true); } else { $options = array('onlyreqdeps' => true); } if ($registry->packageExists($pkg) || $registry->packageExists($pkg_basename)) { print str_pad("Package: {$pkg}", max(50, 9 + strlen($pkg) + 4), '.') . ' already installed ... ok' . "\n"; displayHTMLProgress($progress += round(50 / count($to_install))); continue; } $pkg_basename = substr($pkg, 0, strpos($pkg, '-')); if (in_array($pkg_basename, $bootstrap_pkgs)) { print str_pad("Installing bootstrap package: {$pkg_basename}", max(50, 30 + strlen($pkg_basename) + 4), '.') . "...";
/** * (experimental) * @return array */ private function _getPearOpt(&$cmd_obj, $cmd_str, $opt_array) { $short_args = $long_args = null; PEAR_Command::getGetOptArgs($cmd_str, $short_args, $long_args); $opt = new Ethna_Getopt(); $opt_arg = $opt->getopt($opt_array, $short_args, $long_args); if (Ethna::isError($opt_arg)) { return array(); } $opts = array(); foreach ($opt_arg[0] as $tmp) { list($opt, $val) = $tmp; if ($val === null) { $val = true; } if (strlen($opt) == 1) { $cmd_opts = $cmd_obj->getOptions($cmd_str); foreach ($cmd_opts as $o => $d) { if (isset($d['shortopt']) && $d['shortopt'] == $opt) { $opts[$o] = $val; } } } else { if (substr($opt, 0, 2) == '--') { $opts[substr($opt, 2)] = $val; } } } return $opts; }
/** * Get help for command. * * @param string $command Name of the command to return help for * * @access public * @static */ function getHelp($command) { $cmds = PEAR_Command::getCommands(); if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) { $command = $GLOBALS['_PEAR_Command_shortcuts'][$command]; } if (isset($cmds[$command])) { $obj =& PEAR_Command::getObject($command); return $obj->getHelp($command); } return false; }
function _pear_init() { // Remove E_STRICT from error_reporting error_reporting(error_reporting() & ~E_STRICT); require_once 'PEAR.php'; require_once 'PEAR/Frontend.php'; require_once 'PEAR/Config.php'; require_once 'PEAR/Registry.php'; require_once 'PEAR/Command.php'; require_once 'PEAR/Remote.php'; // current symfony release $sf_version = preg_replace('/\\-\\w+$/', '', file_get_contents(sfConfig::get('sf_symfony_lib_dir') . '/VERSION')); // PEAR PEAR_Command::setFrontendType('CLI'); $ui =& PEAR_Command::getFrontendObject(); // read user/system configuration (don't use the singleton) $config = new PEAR_Config(); $config_file = sfConfig::get('sf_plugins_dir') . DIRECTORY_SEPARATOR . '.pearrc'; // change the configuration for symfony use $config->set('php_dir', sfConfig::get('sf_plugins_dir')); $config->set('data_dir', sfConfig::get('sf_plugins_dir')); $config->set('test_dir', sfConfig::get('sf_plugins_dir')); $config->set('doc_dir', sfConfig::get('sf_plugins_dir')); $config->set('bin_dir', sfConfig::get('sf_plugins_dir')); // change the PEAR temp dir $config->set('cache_dir', sfConfig::get('sf_cache_dir')); $config->set('download_dir', sfConfig::get('sf_cache_dir')); $config->set('tmp_dir', sfConfig::get('sf_cache_dir')); // save out configuration file $config->writeConfigFile($config_file, 'user'); // use our configuration file $config =& PEAR_Config::singleton($config_file); $config->set('verbose', 1); $ui->setConfig($config); date_default_timezone_set('UTC'); // register our channel $symfony_channel = array('attribs' => array('version' => '1.0', 'xmlns' => 'http://pear.php.net/channel-1.0', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation' => 'http://pear.php.net/dtd/channel-1.0 http://pear.php.net/dtd/channel-1.0.xsd'), 'name' => 'pear.symfony-project.com', 'summary' => 'symfony project PEAR channel', 'suggestedalias' => 'symfony', 'servers' => array('primary' => array('rest' => array('baseurl' => array(array('attribs' => array('type' => 'REST1.0'), '_content' => 'http://pear.symfony-project.com/Chiara_PEAR_Server_REST/'), array('attribs' => array('type' => 'REST1.1'), '_content' => 'http://pear.symfony-project.com/Chiara_PEAR_Server_REST/'))))), '_lastmodified' => array('ETag' => "113845-297-dc93f000", 'Last-Modified' => date('r'))); pake_mkdirs(sfConfig::get('sf_plugins_dir') . '/.channels/.alias'); file_put_contents(sfConfig::get('sf_plugins_dir') . '/.channels/pear.symfony-project.com.reg', serialize($symfony_channel)); file_put_contents(sfConfig::get('sf_plugins_dir') . '/.channels/.alias/symfony.txt', 'pear.symfony-project.com'); // register symfony for dependencies $symfony = array('name' => 'symfony', 'channel' => 'pear.symfony-project.com', 'date' => date('Y-m-d'), 'time' => date('H:i:s'), 'version' => array('release' => $sf_version, 'api' => '1.0.0'), 'stability' => array('release' => 'stable', 'api' => 'stable'), 'xsdversion' => '2.0', '_lastmodified' => time(), 'old' => array('version' => $sf_version, 'release_state' => 'stable')); $dir = sfConfig::get('sf_plugins_dir') . DIRECTORY_SEPARATOR . '.registry' . DIRECTORY_SEPARATOR . '.channel.pear.symfony-project.com'; pake_mkdirs($dir); file_put_contents($dir . DIRECTORY_SEPARATOR . 'symfony.reg', serialize($symfony)); return $config; }
function cmdHelp($command) { global $progname, $all_commands, $config; if ($command == "options") { return "Options:\n" . " -v increase verbosity level (default 1)\n" . " -q be quiet, decrease verbosity level\n" . " -c file find user configuration in `file'\n" . " -C file find system configuration in `file'\n" . " -d foo=bar set user config variable `foo' to `bar'\n" . " -D foo=bar set system config variable `foo' to `bar'\n" . " -G start in graphical (Gtk) mode\n" . " -s store user configuration\n" . " -S store system configuration\n" . " -u foo unset `foo' in the user configuration\n" . " -h, -? display help/usage (this message)\n" . " -V version information\n"; } elseif ($command == "shortcuts") { $sc = PEAR_Command::getShortcuts(); $ret = "Shortcuts:\n"; foreach ($sc as $s => $c) { $ret .= sprintf(" %-8s %s\n", $s, $c); } return $ret; } elseif ($command == "version") { return "PEAR Version: " . $GLOBALS['pear_package_version'] . "\nPHP Version: " . phpversion() . "\nZend Engine Version: " . zend_version() . "\nRunning on: " . php_uname(); } elseif ($help = PEAR_Command::getHelp($command)) { if (is_string($help)) { return "{$progname} {$command} [options] {$help}\n"; } if ($help[1] === null) { return "{$progname} {$command} {$help['0']}"; } else { return "{$progname} {$command} [options] {$help['0']}\n{$help['1']}"; } } return "Command '{$command}' is not valid, try 'pear help'"; }
/** * Updates the source for the package. * * We have to update required dependencies automatically to make sure that * everything still works properly. * * It is the developers responsibility to make sure the user is given the * option to update any optional dependencies if needed. This can be done * by creating a new instance of PEAR_PackageUpdate for the optional * dependency. * * @access public * @return boolean true if the update was successful. * @since 0.4.0a1 * @throws PEAR_PACKAGEUPDATE_ERROR_NOTINSTALLED */ function update() { // Create a config object. $config = new PEAR_Config(); // Change the verbosity but keep track of the value to reset it just in // case this does something permanent. $verbose = $config->get('verbose'); $config->set('verbose', 0); // Create a command object to do the upgrade. // If the current version is 0.0.0 don't upgrade. That would be a // sneaky way for devs to install packages without the use knowing. if ($this->instVersion == '0.0.0') { $this->pushError(PEAR_PACKAGEUPDATE_ERROR_NOTINSTALLED, NULL, array('packagename' => $this->packageName)); return false; } require_once 'PEAR/Command.php'; $upgrade = PEAR_Command::factory('upgrade', $config); // Try to upgrade the application. $channelPackage = $this->channel . '/' . $this->packageName; $result = $upgrade->doInstall('upgrade', array('onlyreqdeps' => true), array($channelPackage)); // Reset the verbose level just to be safe. $config->set('verbose', $verbose); // Check for errors. if (PEAR::isError($result)) { $this->pushError($result); return false; } else { return true; } }