mirror of
https://github.com/php/php-src.git
synced 2024-09-23 02:47:26 +00:00
- Implement command level options
- Removed call pass by reference - Readd $options to command::run() params
This commit is contained in:
parent
661fd669ec
commit
a7936eea78
@ -33,6 +33,12 @@ $GLOBALS['_PEAR_Command_commandlist'] = array();
|
||||
*/
|
||||
$GLOBALS['_PEAR_Command_uiclass'] = 'PEAR_CommandUI_CLI';
|
||||
|
||||
/**
|
||||
* The options accepted by the commands
|
||||
* @var string the options
|
||||
*/
|
||||
$GLOBALS['_PEAR_Command_commandopts'] = '';
|
||||
|
||||
/**
|
||||
* PEAR command class, a simple factory class for administrative
|
||||
* commands.
|
||||
@ -154,6 +160,7 @@ class PEAR_Command
|
||||
if (!$merge) {
|
||||
$GLOBALS['_PEAR_Command_commandlist'] = array();
|
||||
}
|
||||
$cmdopts = array();
|
||||
while ($entry = readdir($dp)) {
|
||||
if ($entry{0} == '.' || substr($entry, -4) != '.php' ||
|
||||
$entry == 'Common.php')
|
||||
@ -163,11 +170,15 @@ class PEAR_Command
|
||||
$class = "PEAR_Command_".substr($entry, 0, -4);
|
||||
$file = "$dir/$entry";
|
||||
include_once $file;
|
||||
// List of commands
|
||||
$implements = call_user_func(array($class, "getCommands"));
|
||||
foreach ($implements as $command) {
|
||||
$GLOBALS['_PEAR_Command_commandlist'][$command] = $class;
|
||||
}
|
||||
// List of options accepted
|
||||
$cmdopts = array_merge($cmdopts, call_user_func(array($class, "getOptions")));
|
||||
}
|
||||
$GLOBALS['_PEAR_Command_commandopts'] = implode('', $cmdopts);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -186,6 +197,14 @@ class PEAR_Command
|
||||
}
|
||||
return $GLOBALS['_PEAR_Command_commandlist'];
|
||||
}
|
||||
|
||||
function getOptions()
|
||||
{
|
||||
if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
|
||||
PEAR_Command::registerCommands();
|
||||
}
|
||||
return $GLOBALS['_PEAR_Command_commandopts'];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -49,6 +49,11 @@ class PEAR_Command_Common extends PEAR
|
||||
$this->ui = $ui;
|
||||
}
|
||||
|
||||
function getOptions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a PEAR_CommandResponse object with parameters
|
||||
* filled in.
|
||||
|
@ -59,7 +59,7 @@ class PEAR_Command_Config extends PEAR_Command_Common
|
||||
// }}}
|
||||
// {{{ run()
|
||||
|
||||
function run($command, $params)
|
||||
function run($command, $options, $params)
|
||||
{
|
||||
$cf =& $this->config;
|
||||
$failmsg = '';
|
||||
|
@ -60,22 +60,25 @@ class PEAR_Command_Install extends PEAR_Command_Common
|
||||
// }}}
|
||||
// {{{ run()
|
||||
|
||||
function run($command, $params)
|
||||
function run($command, $options, $params)
|
||||
{
|
||||
$installer =& new PEAR_Installer($this->config->get('php_dir'),
|
||||
$this->config->get('ext_dir'),
|
||||
$this->config->get('doc_dir'));
|
||||
$installer->debug = $this->config->get('verbose');
|
||||
$failmsg = '';
|
||||
$options = array();
|
||||
$opts = array();
|
||||
switch ($command) {
|
||||
case 'install':
|
||||
case 'upgrade': {
|
||||
if ($command == 'upgrade') {
|
||||
$options['upgrade'] = true;
|
||||
$opts['upgrade'] = true;
|
||||
}
|
||||
if (isset($options['f'])) {
|
||||
$opts['force'] = true;
|
||||
}
|
||||
// The ['force'] and ['nodeps'] options are still missing
|
||||
if ($installer->install($params[0], $options, $this->config)) {
|
||||
if ($installer->install(@$params[0], $opts, $this->config)) {
|
||||
$this->ui->displayLine("install ok");
|
||||
} else {
|
||||
$failmsg = "install failed";
|
||||
@ -101,6 +104,11 @@ class PEAR_Command_Install extends PEAR_Command_Common
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
function getOptions()
|
||||
{
|
||||
return array('f');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -59,7 +59,7 @@ class PEAR_Command_List extends PEAR_Command_Common
|
||||
// }}}
|
||||
// {{{ run()
|
||||
|
||||
function run($command, $params)
|
||||
function run($command, $options, $params)
|
||||
{
|
||||
$reg = new PEAR_Registry(); // XXX Use config here
|
||||
$installed = $reg->packageInfo();
|
||||
|
@ -70,7 +70,7 @@ class PEAR_Command_Login extends PEAR_Command_Common
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function run($command, $params)
|
||||
function run($command, $options, $params)
|
||||
{
|
||||
$cf = $this->config;
|
||||
$failmsg = '';
|
||||
|
@ -48,7 +48,7 @@ class PEAR_Command_Package extends PEAR_Command_Common
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function run($command, $params)
|
||||
function run($command, $options, $params)
|
||||
{
|
||||
$failmsg = '';
|
||||
switch ($command) {
|
||||
|
@ -355,7 +355,7 @@ class PEAR_Config extends PEAR
|
||||
$size = filesize($file);
|
||||
$contents = fread($fp, $size);
|
||||
$version = '0.1';
|
||||
if (preg_match('/^#PEAR_Config\s+(\S+)\s+/si', $contents, &$matches)) {
|
||||
if (preg_match('/^#PEAR_Config\s+(\S+)\s+/si', $contents, $matches)) {
|
||||
$version = $matches[1];
|
||||
$contents = substr($contents, strlen($matches[0]));
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ class PEAR_Remote extends PEAR
|
||||
fwrite($fp, ("POST /xmlrpc.php HTTP/1.0\r\n$req_headers\r\n$request"));
|
||||
$response = '';
|
||||
$line1 = fgets($fp, 2048);
|
||||
if (!preg_match('!^HTTP/[0-9\.]+ (\d+) (.*)!', $line1, &$matches)) {
|
||||
if (!preg_match('!^HTTP/[0-9\.]+ (\d+) (.*)!', $line1, $matches)) {
|
||||
return $this->raiseError("PEAR_Remote: invalid HTTP response from XML-RPC server");
|
||||
}
|
||||
switch ($matches[1]) {
|
||||
|
Loading…
Reference in New Issue
Block a user