Source for file Common.php
Documentation is available at Common.php
* PEAR_Command_Common base class
* @author Stig Bakken <ssb@php.net>
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version CVS: $Id: Common.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
* PEAR commands base class
* @author Stig Bakken <ssb@php.net>
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
* 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 (
'prog' => 'external program',
'ldlib' => 'external library for linking',
'rtlib' => 'external runtime library',
'os' => 'operating system',
'websrv' => 'web server',
* PEAR_Command_Common constructor.
* 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;
if (isset ($shortcuts[$command])) {
$command = $shortcuts[$command];
if (isset ($this->commands[$command]) &&
isset ($this->commands[$command]['options'])) {
return $this->commands[$command]['options'];
if (empty ($this->commands[$command]) || empty ($this->commands[$command]['options'])) {
reset($this->commands[$command]['options']);
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
if (!isset ($this->commands[$command])) {
return " No such command \"$command\"";
if (isset ($this->commands[$command]['doc'])) {
$help = $this->commands[$command]['doc'];
// XXX (cox) Fallback to summary if there is no doc (show both?)
if (!isset ($this->commands[$command]['summary'])) {
return " No help for command \"$command\"";
$help = $this->commands[$command]['summary'];
foreach($matches[0 ] as $k => $v) {
$help = preg_replace(" /$v/" , $config->get ($matches[1 ][$k]), $help);
* Returns the help for the accepted arguments of a command
* @return string The help string
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";
function run($command, $options, $params)
if (empty ($this->commands[$command]['function'])) {
if (isset ($this->commands[$cmd]['shortcut']) && $this->commands[$cmd]['shortcut'] == $command) {
if (empty ($this->commands[$cmd]['function'])) {
return $this->raiseError(" unknown command `$command'" );
$func = $this->commands[$cmd]['function'];
//$command = $this->commands[$cmd]['function'];
$func = $this->commands[$command]['function'];
return $this->$func($command, $options, $params);
Documentation generated on Wed, 06 Jul 2011 23:30:34 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.
|