[ class tree: PEAR ] [ index: PEAR ] [ all elements ]

Class: PEAR_Command

Source Location: /PEAR-1.9.5/PEAR/Command.php

Class Overview

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



  • Release: 1.9.5


  • 1997-2009 The Authors


Inherited Variables

Inherited Methods

Class Details

[line 101]
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().

[ Top ]

Method Detail

factory   [line 116]

object the &factory( string $command, &$config, object $config)

Get the right object for executing a command.
  • Return: command object or a PEAR error
  • Access: public


string   $command     The name of the command
object   $config     Instance of PEAR_Config object

[ Top ]

getCommands   [line 312]

array getCommands( )

Get the list of currently supported commands, and what classes implement them.
  • Return: command => implementing class
  • Access: public

[ Top ]

getDescription   [line 382]

string getDescription( string $command)

Get description for a command.
  • Return: command description
  • Access: public


string   $command     Name of the command

[ Top ]

getFrontendObject   [line 167]

object|PEAR_Error &getFrontendObject( )

Get instance of frontend object.

[ Top ]

getGetoptArgs   [line 354]

void getGetoptArgs( string $command, &$short_args, &$long_args, string $short_args, array $long_args)

Compiles arguments for getopt.
  • Access: public


string   $command     command to get optstring for
string   $short_args     (reference) short getopt format
array   $long_args     (reference) long getopt format

[ Top ]

getHelp   [line 401]

void getHelp( string $command)

Get help for command.
  • Access: public


string   $command     Name of the command to return help for

[ Top ]

getObject   [line 143]

void &getObject( $command)



[ Top ]

getShortcuts   [line 331]

array getShortcuts( )

Get the list of command shortcuts.
  • Return: shortcut => command
  • Access: public

[ Top ]

registerCommands   [line 228]

bool registerCommands( [bool $merge = false], [string $dir = null])

Scan through the Command directory looking for classes and see what commands they implement.
  • Return: TRUE on success, a PEAR error on failure
  • Access: public


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.

[ Top ]

setFrontendClass   [line 184]

object the &setFrontendClass( string $uiclass)

Load current frontend class.
  • Return: frontend object, or a PEAR error


string   $uiclass     Name of class implementing the frontend

[ Top ]

setFrontendType   [line 201]

object the setFrontendType( string $uitype)

Set current frontend.
  • Return: frontend object, or a PEAR error


string   $uitype     Name of the frontend type (for example "CLI")

[ Top ]

Documentation generated on Sat, 12 Jul 2014 14:00:28 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.