Subversion Repositories Applications.gtt

Compare Revisions

Ignore whitespace Rev 94 → Rev 187

/trunk/bibliotheque/pear/PEAR/Command/Common.php
4,19 → 4,12
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* 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 web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category pear
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2006 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: Common.php,v 1.35 2006/06/08 22:25:18 pajoye Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
33,16 → 26,14
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2006 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.5.1
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
class PEAR_Command_Common extends PEAR
{
// {{{ properties
 
/**
* PEAR_Config object used to pass user system and configuration
* on when executing commands
84,25 → 75,18
'sapi' => 'SAPI backend'
);
 
// }}}
// {{{ constructor
 
/**
* PEAR_Command_Common constructor.
*
* @access public
*/
function PEAR_Command_Common(&$ui, &$config)
function __construct(&$ui, &$config)
{
parent::PEAR();
parent::__construct();
$this->config = &$config;
$this->ui = &$ui;
}
 
// }}}
 
// {{{ getCommands()
 
/**
* Return a list of all the commands defined by this class.
* @return array list of commands
114,12 → 98,10
foreach (array_keys($this->commands) as $command) {
$ret[$command] = $this->commands[$command]['summary'];
}
 
return $ret;
}
 
// }}}
// {{{ getShortcuts()
 
/**
* Return a list of all the command shortcuts defined by this class.
* @return array shortcut => command
133,12 → 115,10
$ret[$this->commands[$command]['shortcut']] = $command;
}
}
 
return $ret;
}
 
// }}}
// {{{ getOptions()
 
function getOptions($command)
{
$shortcuts = $this->getShortcuts();
145,24 → 125,23
if (isset($shortcuts[$command])) {
$command = $shortcuts[$command];
}
 
if (isset($this->commands[$command]) &&
isset($this->commands[$command]['options'])) {
return $this->commands[$command]['options'];
} else {
return null;
}
 
return null;
}
 
// }}}
// {{{ getGetoptArgs()
 
function getGetoptArgs($command, &$short_args, &$long_args)
{
$short_args = "";
$short_args = '';
$long_args = array();
if (empty($this->commands[$command]) || empty($this->commands[$command]['options'])) {
return;
}
 
reset($this->commands[$command]['options']);
while (list($option, $info) = each($this->commands[$command]['options'])) {
$larg = $sarg = '';
177,15 → 156,15
$arg = $info['arg'];
}
}
 
if (isset($info['shortopt'])) {
$short_args .= $info['shortopt'] . $sarg;
}
 
$long_args[] = $option . $larg;
}
}
 
// }}}
// {{{ getHelp()
/**
* Returns the help message for the given command
*
200,10 → 179,12
if (!isset($this->commands[$command])) {
return "No such command \"$command\"";
}
 
$help = null;
if (isset($this->commands[$command]['doc'])) {
$help = $this->commands[$command]['doc'];
}
 
if (empty($help)) {
// XXX (cox) Fallback to summary if there is no doc (show both?)
if (!isset($this->commands[$command]['summary'])) {
211,22 → 192,22
}
$help = $this->commands[$command]['summary'];
}
 
if (preg_match_all('/{config\s+([^\}]+)}/e', $help, $matches)) {
foreach($matches[0] as $k => $v) {
$help = preg_replace("/$v/", $config->get($matches[1][$k]), $help);
}
}
 
return array($help, $this->getHelpArgs($command));
}
 
// }}}
// {{{ getHelpArgs()
/**
* Returns the help for the accepted arguments of a command
*
* @param string $command
* @return string The help string
*/
* Returns the help for the accepted arguments of a command
*
* @param string $command
* @return string The help string
*/
function getHelpArgs($command)
{
if (isset($this->commands[$command]['options']) &&
246,6 → 227,7
} else {
$sapp = $lapp = "";
}
 
if (isset($v['shortopt'])) {
$s = $v['shortopt'];
$help .= " -$s$sapp, --$k$lapp\n";
252,18 → 234,18
} else {
$help .= " --$k$lapp\n";
}
 
$p = " ";
$doc = rtrim(str_replace("\n", "\n$p", $v['doc']));
$help .= " $doc\n";
}
 
return $help;
}
 
return null;
}
 
// }}}
// {{{ run()
 
function run($command, $options, $params)
{
if (empty($this->commands[$command]['function'])) {
276,6 → 258,8
$func = $this->commands[$cmd]['function'];
}
$command = $cmd;
 
//$command = $this->commands[$cmd]['function'];
break;
}
}
282,10 → 266,7
} else {
$func = $this->commands[$command]['function'];
}
 
return $this->$func($command, $options, $params);
}
 
// }}}
}
 
?>