From: Stig Bakken Date: Mon, 20 May 2002 08:56:00 +0000 (+0000) Subject: * remove run() from this class X-Git-Tag: RELEASE_0_4~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=845e6f86bc570c7ede39dc2ff1a540fe867f9cb2;p=php * remove run() from this class --- diff --git a/pear/PEAR/Command/Registry.php b/pear/PEAR/Command/Registry.php index be5bf182a8..fa6114cece 100644 --- a/pear/PEAR/Command/Registry.php +++ b/pear/PEAR/Command/Registry.php @@ -25,7 +25,24 @@ require_once 'PEAR/Config.php'; class PEAR_Command_Registry extends PEAR_Command_Common { - // {{{ constructor + var $commands = array( + 'list-installed' => array( + 'summary' => 'List Installed Packages', + 'function' => 'doListInstalled', + 'options' => array(), + 'doc' => 'List the PEAR packages installed in your php_dir ({config php_dir)). +', + ), + 'shell-test' => array( + 'summary' => 'Shell Script Test', + 'function' => 'doShellTest', + 'options' => array(), + 'doc' => 'Tests if a package is installed in the system. Will exit(1) if it is not. + The version comparison operator. One of: + <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne + The version to compare with +'), + ); /** * PEAR_Command_Registry constructor. @@ -37,125 +54,58 @@ class PEAR_Command_Registry extends PEAR_Command_Common parent::PEAR_Command_Common($ui, $config); } - // }}} - - // {{{ getCommands() - - /** - * Return a list of all the commands defined by this class. - * @return array list of commands - * @access public - */ - function getCommands() - { - return array('list-installed' => 'List Installed Packages', - 'shell-test' => 'Shell Script Test'); - } - - function getHelp($command) + function doListInstalled($command, $options, $params) { - switch ($command) { - case 'list-installed': - return array(null, 'List the installed PEAR packages in the system'); - case 'shell-test': - return array(' [] []', - "Tests if a package is installed in the system. Will exit(1) if it is not.\n". - " The version comparison operator. One of:\n". - " <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne\n". - " The version to compare with"); + $reg = new PEAR_Registry($this->config->get('php_dir')); + $installed = $reg->packageInfo(); + $i = $j = 0; + $this->ui->startTable( + array('caption' => 'Installed packages:', + 'border' => true)); + foreach ($installed as $package) { + if ($i++ % 20 == 0) { + $this->ui->tableRow( + array('Package', 'Version', 'State'), + array('bold' => true)); + } + $this->ui->tableRow(array($package['package'], + $package['version'], + @$package['release_state'])); } + if ($i == 0) { + $this->ui->tableRow(array('(no packages installed yet)')); + } + $this->ui->endTable(); + return true; } - // }}} - // {{{ run() - - /** - * Execute the command. - * - * @param string command name - * - * @param array option_name => value - * - * @param array list of additional parameters - * - * @return bool TRUE on success, FALSE if the command was unknown, - * or a PEAR error on failure - * - * @access public - */ - function run($command, $options, $params) - { - $failmsg = ''; - $cf = &PEAR_Config::singleton(); - switch ($command) { - // {{{ list-installed - - case 'list-installed': { - $reg = new PEAR_Registry($cf->get('php_dir')); - $installed = $reg->packageInfo(); - $i = $j = 0; - $this->ui->startTable( - array('caption' => 'Installed packages:', - 'border' => true)); - foreach ($installed as $package) { - if ($i++ % 20 == 0) { - $this->ui->tableRow( - array('Package', 'Version', 'State'), - array('bold' => true)); - } - $this->ui->tableRow(array($package['package'], - $package['version'], - @$package['release_state'])); - } - if ($i == 0) { - $this->ui->tableRow(array('(no packages installed yet)')); - } - $this->ui->endTable(); - break; + function doShellTest($command, $options, $params) { + $this->pushErrorHandling(PEAR_ERROR_RETURN); + $reg = &new PEAR_Registry($this->config->get('php_dir')); + // "pear shell-test Foo" + if (sizeof($params) == 1) { + if (!$reg->packageExists($params[0])) { + exit(1); } - - // }}} - case 'shell-test': { - // silence error messages for the rest of the execution - PEAR::pushErrorHandling(PEAR_ERROR_RETURN); - $reg = &new PEAR_Registry($this->config->get('php_dir')); - // "pear shell-test Foo" - if (sizeof($params) == 1) { - if (!$reg->packageExists($params[0])) { - exit(1); - } - // "pear shell-test Foo 1.0" - } elseif (sizeof($params) == 2) { - $v = $reg->packageInfo($params[0], 'version'); - if (!$v || !version_compare($v, $params[1], "ge")) { - exit(1); - } - // "pear shell-test Foo ge 1.0" - } elseif (sizeof($params) == 3) { - $v = $reg->packageInfo($params[0], 'version'); - if (!$v || !version_compare($v, $params[2], $params[1])) { - exit(1); - } - } else { - PEAR::popErrorHandling(); - PEAR::raiseError("$command: expects 1 to 3 parameters"); - exit(1); - } - break; + // "pear shell-test Foo 1.0" + } elseif (sizeof($params) == 2) { + $v = $reg->packageInfo($params[0], 'version'); + if (!$v || !version_compare($v, $params[1], "ge")) { + exit(1); } - default: { - return false; + // "pear shell-test Foo ge 1.0" + } elseif (sizeof($params) == 3) { + $v = $reg->packageInfo($params[0], 'version'); + if (!$v || !version_compare($v, $params[2], $params[1])) { + exit(1); } + } else { + $this->popErrorHandling(); + $this->raiseError("$command: expects 1 to 3 parameters"); + exit(1); } - if ($failmsg) { - return $this->raiseError($failmsg); - } - return true; } - // }}} - - } ?> \ No newline at end of file