Bearsampp 2026.9.23
Loading...
Searching...
No Matches
PEAR_Command Class Reference

Static Public Member Functions

static & factory ($command, &$config)
static getCommands ()
static getDescription ($command)
static & getFrontendObject ()
static getGetoptArgs ($command, &$short_args, &$long_args)
static getHelp ($command)
static & getObject ($command)
static getShortcuts ()
static registerCommands ($merge=false, $dir=null)
static & setFrontendClass ($uiclass)
static setFrontendType ($uitype)

Detailed Description

Definition at line 100 of file Command.php.

Member Function Documentation

◆ factory()

& factory ( $command,
& $config )
static

Get the right object for executing a command.

Parameters
string$commandThe name of the command
object$configInstance of PEAR_Config object
Returns
object the command object or a PEAR error

Definition at line 112 of file Command.php.

113 {
114 if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
116 }
117 if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) {
118 $command = $GLOBALS['_PEAR_Command_shortcuts'][$command];
119 }
120 if (!isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
121 $a = PEAR::raiseError("unknown command `$command'");
122 return $a;
123 }
124 $class = $GLOBALS['_PEAR_Command_commandlist'][$command];
125 if (!class_exists($class)) {
126 require_once $GLOBALS['_PEAR_Command_objects'][$class];
127 }
128 if (!class_exists($class)) {
129 $a = PEAR::raiseError("unknown command `$command'");
130 return $a;
131 }
133 $obj = new $class($ui, $config);
134 return $obj;
135 }
$GLOBALS['_PEAR_Command_commandlist']
Definition Command.php:28
static registerCommands($merge=false, $dir=null)
Definition Command.php:218
static & getFrontendObject()
Definition Command.php:162
$config
Definition pearcmd.php:182
$ui
Definition pearcmd.php:181
if( $raw) foreach($opts as $opt) if( $store_system_config) if($store_user_config) $command
Definition pearcmd.php:322

References $command, $config, $GLOBALS, $ui, getFrontendObject(), and registerCommands().

Referenced by PEAR_Command_Mirror\factory().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCommands()

getCommands ( )
static

Get the list of currently supported commands, and what classes implement them.

Returns
array command => implementing class

Definition at line 299 of file Command.php.

300 {
301 if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
303 }
304 return $GLOBALS['_PEAR_Command_commandlist'];
305 }

References $GLOBALS, and registerCommands().

Referenced by getHelp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDescription()

getDescription ( $command)
static

Get description for a command.

Parameters
string$commandName of the command
Returns
string command description

Definition at line 360 of file Command.php.

361 {
362 if (!isset($GLOBALS['_PEAR_Command_commanddesc'][$command])) {
363 return null;
364 }
365 return $GLOBALS['_PEAR_Command_commanddesc'][$command];
366 }

References $command, and $GLOBALS.

Referenced by usage().

Here is the caller graph for this function:

◆ getFrontendObject()

& getFrontendObject ( )
static

Get instance of frontend object.

Returns
object|PEAR_Error

Definition at line 162 of file Command.php.

163 {
165 return $a;
166 }
static & singleton($type=null)
Definition Frontend.php:51

References PEAR_Frontend\singleton().

Referenced by factory(), and getObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getGetoptArgs()

getGetoptArgs ( $command,
& $short_args,
& $long_args )
static

Compiles arguments for getopt.

Parameters
string$commandcommand to get optstring for
string$short_args(reference) short getopt format
array$long_args(reference) long getopt format
Returns
void

Definition at line 335 of file Command.php.

336 {
337 if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
339 }
340 if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) {
341 $command = $GLOBALS['_PEAR_Command_shortcuts'][$command];
342 }
343 if (!isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
344 return null;
345 }
347 return $obj->getGetoptArgs($command, $short_args, $long_args);
348 }
static & getObject($command)
Definition Command.php:139

References $command, $GLOBALS, getObject(), and registerCommands().

Here is the call graph for this function:

◆ getHelp()

getHelp ( $command)
static

Get help for command.

Parameters
string$commandName of the command to return help for

Definition at line 376 of file Command.php.

377 {
379 if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) {
380 $command = $GLOBALS['_PEAR_Command_shortcuts'][$command];
381 }
382 if (isset($cmds[$command])) {
384 return $obj->getHelp($command);
385 }
386 return false;
387 }
static getCommands()
Definition Command.php:299

References $command, $GLOBALS, getCommands(), and getObject().

Referenced by cmdHelp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getObject()

& getObject ( $command)
static

Definition at line 139 of file Command.php.

140 {
141 $class = $GLOBALS['_PEAR_Command_commandlist'][$command];
142 if (!class_exists($class)) {
143 require_once $GLOBALS['_PEAR_Command_objects'][$class];
144 }
145 if (!class_exists($class)) {
146 return PEAR::raiseError("unknown command `$command'");
147 }
149 $config = &PEAR_Config::singleton();
150 $obj = new $class($ui, $config);
151 return $obj;
152 }

References $command, $config, $GLOBALS, $ui, and getFrontendObject().

Referenced by getGetoptArgs(), and getHelp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getShortcuts()

getShortcuts ( )
static

Get the list of command shortcuts.

Returns
array shortcut => command

Definition at line 315 of file Command.php.

316 {
317 if (empty($GLOBALS['_PEAR_Command_shortcuts'])) {
319 }
320 return $GLOBALS['_PEAR_Command_shortcuts'];
321 }

References $GLOBALS, and registerCommands().

Referenced by cmdHelp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ registerCommands()

registerCommands ( $merge = false,
$dir = null )
static

Scan through the Command directory looking for classes and see what commands they implement.

Parameters
bool(optional) if FALSE (default), the new list of commands should replace the current one. If TRUE, new entries will be merged with old.
string(optional) where (what directory) to look for classes, defaults to the Command subdirectory of the directory from where this file (FILE) is included.
Returns
bool TRUE on success, a PEAR error on failure

Definition at line 218 of file Command.php.

219 {
220 $parser = new PEAR_XMLParser;
221 if ($dir === null) {
222 $dir = dirname(__FILE__) . '/Command';
223 }
224 if (!is_dir($dir)) {
225 return PEAR::raiseError("registerCommands: opendir($dir) '$dir' does not exist or is not a directory");
226 }
227 $dp = @opendir($dir);
228 if (empty($dp)) {
229 return PEAR::raiseError("registerCommands: opendir($dir) failed");
230 }
231 if (!$merge) {
232 $GLOBALS['_PEAR_Command_commandlist'] = array();
233 }
234
235 while ($file = readdir($dp)) {
236 if ($file[0] == '.' || substr($file, -4) != '.xml') {
237 continue;
238 }
239
240 $f = substr($file, 0, -4);
241 $class = "PEAR_Command_" . $f;
242 // List of commands
243 if (empty($GLOBALS['_PEAR_Command_objects'][$class])) {
244 $GLOBALS['_PEAR_Command_objects'][$class] = "$dir/" . $f . '.php';
245 }
246
247 $parser->parse(file_get_contents("$dir/$file"));
248 $implements = $parser->getData();
249 foreach ($implements as $command => $desc) {
250 if ($command == 'attribs') {
251 continue;
252 }
253
254 if (isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
255 return PEAR::raiseError('Command "' . $command . '" already registered in ' .
256 'class "' . $GLOBALS['_PEAR_Command_commandlist'][$command] . '"');
257 }
258
259 $GLOBALS['_PEAR_Command_commandlist'][$command] = $class;
260 $GLOBALS['_PEAR_Command_commanddesc'][$command] = $desc['summary'];
261 if (isset($desc['shortcut'])) {
262 $shortcut = $desc['shortcut'];
263 if (isset($GLOBALS['_PEAR_Command_shortcuts'][$shortcut])) {
264 return PEAR::raiseError('Command shortcut "' . $shortcut . '" already ' .
265 'registered to command "' . $command . '" in class "' .
266 $GLOBALS['_PEAR_Command_commandlist'][$command] . '"');
267 }
268 $GLOBALS['_PEAR_Command_shortcuts'][$shortcut] = $command;
269 }
270
271 if (isset($desc['options']) && $desc['options']) {
272 foreach ($desc['options'] as $oname => $option) {
273 if (isset($option['shortopt']) && strlen($option['shortopt']) > 1) {
274 return PEAR::raiseError('Option "' . $oname . '" short option "' .
275 $option['shortopt'] . '" must be ' .
276 'only 1 character in Command "' . $command . '" in class "' .
277 $class . '"');
278 }
279 }
280 }
281 }
282 }
283
284 ksort($GLOBALS['_PEAR_Command_shortcuts']);
285 ksort($GLOBALS['_PEAR_Command_commandlist']);
286 @closedir($dp);
287 return true;
288 }

References $command, and $GLOBALS.

Referenced by factory(), getCommands(), getGetoptArgs(), and getShortcuts().

Here is the caller graph for this function:

◆ setFrontendClass()

& setFrontendClass ( $uiclass)
static

Load current frontend class.

Parameters
string$uiclassName of class implementing the frontend
Returns
object the frontend object, or a PEAR error

Definition at line 178 of file Command.php.

179 {
180 $a = &PEAR_Frontend::setFrontendClass($uiclass);
181 return $a;
182 }
static & setFrontendClass($uiclass)
Definition Frontend.php:73

References PEAR_Frontend\setFrontendClass().

Referenced by setFrontendType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFrontendType()

setFrontendType ( $uitype)
static

Set current frontend.

Parameters
string$uitypeName of the frontend type (for example "CLI")
Returns
object the frontend object, or a PEAR error

Definition at line 194 of file Command.php.

195 {
196 $uiclass = 'PEAR_Frontend_' . $uitype;
197 return PEAR_Command::setFrontendClass($uiclass);
198 }
static & setFrontendClass($uiclass)
Definition Command.php:178

References setFrontendClass().

Here is the call graph for this function:

The documentation for this class was generated from the following file:
  • E:/Bearsampp-development/sandbox/core/libs/php/pear/pear/PEAR/Command.php