4 * Commands for the PHP_Shell
6 * Extensions can register their own commands for the shell like the
7 * InlineHelp Extension which provides inline help for all functions
9 * It uses the pattern '? <string>' to catch the cmdline strings.
11 * registerCommand() should be called by the extensions in the register()
12 * method. Its parameters are
13 * - the regex which matches the command
14 * - the object and the method to call if the command is matched
15 * - the human readable command string and the description for the help
17 class PHP_Shell_Commands {
19 * instance of the current class
21 * @var PHP_Shell_Commands
23 static protected $instance;
28 * array('quit' => ... )
31 * @see registerCommand
33 protected $commands = array();
36 * register your own command for the shell
38 * @param string $regex a regex to match against the input line
39 * @param string $obj a Object
40 * @param string $method a method in the object to call of the regex matches
41 * @param string $cmd the command string for the help
42 * @param string $help the full help description for this command
44 public function registerCommand($regex, $obj, $method, $cmd, $help) {
45 $this->commands[] = array(
50 'description' => $help
55 * return a copy of the commands array
57 * @return all commands
59 public function getCommands() {
60 return $this->commands;
63 static function getInstance() {
64 if (is_null(self::$instance)) {
66 self::$instance = new $class();
68 return self::$instance;