summaryrefslogtreecommitdiff
path: root/framework/3rdParty/PhpShell/PHP/Shell/Commands.php
diff options
context:
space:
mode:
authorxue <>2006-09-23 01:51:57 +0000
committerxue <>2006-09-23 01:51:57 +0000
commita5467e842316daf6a8a4345740f05a9731167ce1 (patch)
tree0a982dd52df5c682fd2de8f9b22137471cee2dbe /framework/3rdParty/PhpShell/PHP/Shell/Commands.php
parent9af56fd93ed071d86f14296cec618073f6c0941a (diff)
merge from 3.0 branch till 1435.
Diffstat (limited to 'framework/3rdParty/PhpShell/PHP/Shell/Commands.php')
-rw-r--r--framework/3rdParty/PhpShell/PHP/Shell/Commands.php72
1 files changed, 72 insertions, 0 deletions
diff --git a/framework/3rdParty/PhpShell/PHP/Shell/Commands.php b/framework/3rdParty/PhpShell/PHP/Shell/Commands.php
new file mode 100644
index 00000000..5a5e7e9b
--- /dev/null
+++ b/framework/3rdParty/PhpShell/PHP/Shell/Commands.php
@@ -0,0 +1,72 @@
+<?php
+
+/**
+* Commands for the PHP_Shell
+*
+* Extensions can register their own commands for the shell like the
+* InlineHelp Extension which provides inline help for all functions
+*
+* It uses the pattern '? <string>' to catch the cmdline strings.
+*
+* registerCommand() should be called by the extensions in the register()
+* method. Its parameters are
+* - the regex which matches the command
+* - the object and the method to call if the command is matched
+* - the human readable command string and the description for the help
+*/
+class PHP_Shell_Commands {
+ /*
+ * instance of the current class
+ *
+ * @var PHP_Shell_Commands
+ */
+ static protected $instance;
+
+ /**
+ * registered commands
+ *
+ * array('quit' => ... )
+ *
+ * @var array
+ * @see registerCommand
+ */
+ protected $commands = array();
+
+ /**
+ * register your own command for the shell
+ *
+ * @param string $regex a regex to match against the input line
+ * @param string $obj a Object
+ * @param string $method a method in the object to call of the regex matches
+ * @param string $cmd the command string for the help
+ * @param string $help the full help description for this command
+ */
+ public function registerCommand($regex, $obj, $method, $cmd, $help) {
+ $this->commands[] = array(
+ 'regex' => $regex,
+ 'obj' => $obj,
+ 'method' => $method,
+ 'command' => $cmd,
+ 'description' => $help
+ );
+ }
+
+ /**
+ * return a copy of the commands array
+ *
+ * @return all commands
+ */
+ public function getCommands() {
+ return $this->commands;
+ }
+
+ static function getInstance() {
+ if (is_null(self::$instance)) {
+ $class = __CLASS__;
+ self::$instance = new $class();
+ }
+ return self::$instance;
+ }
+}
+
+