diff options
author | emkael <emkael@tlen.pl> | 2016-02-24 23:18:07 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-02-24 23:18:07 +0100 |
commit | 6f7fdef0f500cd4bb540affd3bc1482243f337c1 (patch) | |
tree | 4853eecd0769a903e6130c1896e1d070848150dd /lib/prado/framework/3rdParty/PhpShell/PHP/Shell/Commands.php | |
parent | 61f2ea48a4e11cb5fb941b3783e19c9e9ef38a45 (diff) |
* Prado 3.3.0
Diffstat (limited to 'lib/prado/framework/3rdParty/PhpShell/PHP/Shell/Commands.php')
-rw-r--r-- | lib/prado/framework/3rdParty/PhpShell/PHP/Shell/Commands.php | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/lib/prado/framework/3rdParty/PhpShell/PHP/Shell/Commands.php b/lib/prado/framework/3rdParty/PhpShell/PHP/Shell/Commands.php new file mode 100644 index 0000000..3d4bf5b --- /dev/null +++ b/lib/prado/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; + } +} + + |