Class PEAR_Command

Description

PEAR command class, a simple factory class for administrative commands.

How to implement command classes:

  • The class must be called PEAR_Command_Nnn, installed in the "PEAR/Common" subdir, with a method called getCommands() that returns an array of the commands implemented by the class (see PEAR/Command/Install.php for an example).
  • The class must implement a run() function that is called with three params:
(string) command name (array) assoc array with options, freely defined by each command, for example: array('force' => true) (array) list of the other parameters

The run() function returns a PEAR_CommandResponse object. Use these methods to get information:

int getStatus() Returns PEAR_COMMAND_(SUCCESS|FAILURE|PARTIAL) *_PARTIAL means that you need to issue at least one more command to complete the operation (used for example for validation steps).

string getMessage() Returns a message for the user. Remember, no HTML or other interface-specific markup.

If something unexpected happens, run() returns a PEAR error.

  • DON'T OUTPUT ANYTHING! Return text for output instead.
  • DON'T USE HTML! The text you return will be used from both Gtk, web and command-line interfaces, so for now, keep everything to plain text.
  • DON'T USE EXIT OR DIE! Always use pear errors. From static classes do PEAR::raiseError(), from other classes do $this->raiseError().

Located in /maintenance/libraries/pear/PEAR/Command.php (line 97)


	
			
Method Summary
 object the factory (string $command, object &$config)
 array getCommands ()
 string getDescription (string $command)
 object &getFrontendObject ()
 void getGetoptArgs (string $command, string &$short_args, array &$long_args)
 void getHelp (string $command)
 array getShortcuts ()
 boolean isIncludeable (string $path)
 bool registerCommands ([bool $merge = false], [string $dir = null])
 object the &setFrontendClass (string $uiclass)
 object the setFrontendType (string $uitype)
Methods
factory (line 112)

Get the right object for executing a command.

  • return: command object or a PEAR error
  • static:
  • access: public
object the factory (string $command, object &$config)
  • string $command: The name of the command
  • object $config: Instance of PEAR_Config object
getCommands (line 299)

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

  • return: command => implementing class
  • static:
  • access: public
array getCommands ()
getDescription (line 367)

Get description for a command.

  • return: command description
  • static:
  • access: public
string getDescription (string $command)
  • string $command: Name of the command
getFrontendObject (line 141)

Get instance of frontend object.

  • static:
object &getFrontendObject ()
getGetoptArgs (line 341)

Compiles arguments for getopt.

  • static:
  • access: public
void getGetoptArgs (string $command, string &$short_args, array &$long_args)
  • string $command: command to get optstring for
  • string $short_args: (reference) short getopt format
  • array $long_args: (reference) long getopt format
getHelp (line 386)

Get help for command.

  • static:
  • access: public
void getHelp (string $command)
  • string $command: Name of the command to return help for
getShortcuts (line 318)

Get the list of command shortcuts.

  • return: shortcut => command
  • static:
  • access: public
array getShortcuts ()
isIncludeable (line 200)
  • static:
boolean isIncludeable (string $path)
  • string $path: relative or absolute include path
registerCommands (line 250)

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

  • return: TRUE on success, a PEAR error on failure
  • static:
  • access: public
bool registerCommands ([bool $merge = false], [string $dir = null])
  • bool $merge: (optional) if FALSE (default), the new list of commands should replace the current one. If TRUE, new entries will be merged with old.
  • string $dir: (optional) where (what directory) to look for classes, defaults to the Command subdirectory of the directory from where this file (__FILE__) is included.
setFrontendClass (line 160)

Load current frontend class.

  • return: frontend object, or a PEAR error
  • static:
object the &setFrontendClass (string $uiclass)
  • string $uiclass: Name of class implementing the frontend
setFrontendType (line 223)

Set current frontend.

  • return: frontend object, or a PEAR error
  • static:
object the setFrontendType (string $uitype)
  • string $uitype: Name of the frontend type (for example "CLI")

Documentation generated on Fri, 24 Dec 2004 13:01:42 +0000 by phpDocumentor 1.3.0RC3