Source for file Common.php
Documentation is available at Common.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | 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 world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// $Id: Common.php,v 1.24 2004/01/08 17:33:13 sniper Exp $
class PEAR_Command_Common extends PEAR
* PEAR_Config object used to pass user system and configuration
* on when executing commands
* User Interface object, for all interaction with the user.
var $_deps_rel_trans = array (
var $_deps_type_trans = array (
'extension' => 'extension',
'prog' => 'external program',
'ldlib' => 'external library for linking',
'rtlib' => 'external runtime library',
'os' => 'operating system',
'websrv' => 'web server',
* PEAR_Command_Common constructor.
function PEAR_Command_Common (&$ui, &$config)
$this->config = &$config;
* Return a list of all the commands defined by this class.
* @return array list of commands
foreach (array_keys($this->commands) as $command) {
$ret[$command] = $this->commands[$command]['summary'];
* Return a list of all the command shortcuts defined by this class.
* @return array shortcut => command
foreach (array_keys($this->commands) as $command) {
if (isset ($this->commands[$command]['shortcut'])) {
$ret[$this->commands[$command]['shortcut']] = $command;
function getOptions ($command)
return @$this->commands[$command]['options'];
function getGetoptArgs ($command, &$short_args, &$long_args)
if (empty ($this->commands[$command])) {
reset($this->commands[$command]);
while (list ($option, $info) = each($this->commands[$command]['options'])) {
if (isset ($info['arg'])) {
if ($info['arg']{0 } == '(') {
$arg = substr($info['arg'], 1 , -1 );
if (isset ($info['shortopt'])) {
$short_args .= $info['shortopt'] . $sarg;
$long_args[] = $option . $larg;
* Returns the help message for the given command
* @param string $command The command
* @return mixed A fail string if the command does not have help or
* a two elements array containing [0]=>help string,
* [1]=> help string for the accepted cmd args
function getHelp ($command)
$config = &PEAR_Config ::singleton ();
$help = @$this->commands[$command]['doc'];
// XXX (cox) Fallback to summary if there is no doc (show both?)
if (!$help = @$this->commands[$command]['summary']) {
return " No help for command \"$command\"";
foreach($matches[0 ] as $k => $v) {
$help = preg_replace(" /$v/" , $config->get ($matches[1 ][$k]), $help);
return array ($help, $this->getHelpArgs ($command));
* Returns the help for the accepted arguments of a command
* @return string The help string
function getHelpArgs ($command)
if (isset ($this->commands[$command]['options']) &&
count($this->commands[$command]['options']))
foreach ($this->commands[$command]['options'] as $k => $v) {
if ($v['arg']{0 } == '(') {
$arg = substr($v['arg'], 1 , -1 );
if (isset ($v['shortopt'])) {
@$help .= " -$s$sapp, --$k$lapp\n";
@$help .= " --$k$lapp\n";
function run ($command, $options, $params)
$func = @$this->commands[$command]['function'];
if (@$this->commands[$cmd]['shortcut'] == $command) {
$func = @$this->commands[$command]['function'];
return $this->raiseError (" unknown command `$command'" );
return $this->$func($command, $options, $params);
Documentation generated on Mon, 11 Mar 2019 14:23:54 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|