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

Source for file Commands.php

Documentation is available at Commands.php

  1. <?php
  2.  
  3. /**
  4. * Commands for the PHP_Shell
  5. *
  6. * Extensions can register their own commands for the shell like the
  7. * InlineHelp Extension which provides inline help for all functions
  8. *
  9. * It uses the pattern '? <string>' to catch the cmdline strings.
  10. *
  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
  16. */
  17. class PHP_Shell_Commands {
  18.     /*
  19.     * instance of the current class
  20.     *
  21.     * @var PHP_Shell_Commands
  22.     */
  23.     static protected $instance;
  24.  
  25.     /**
  26.     * registered commands
  27.     *
  28.     * array('quit' => ... )
  29.     *
  30.     * @var array 
  31.     * @see registerCommand
  32.     */
  33.     protected $commands = array();
  34.  
  35.     /**
  36.     * register your own command for the shell
  37.     *
  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
  43.     */
  44.     public function registerCommand($regex$obj$method$cmd$help{
  45.         $this->commands[= array(
  46.             'regex' => $regex,
  47.             'obj' => $obj,
  48.             'method' => $method,
  49.             'command' => $cmd,
  50.             'description' => $help
  51.         );
  52.     }
  53.  
  54.     /**
  55.     * return a copy of the commands array
  56.     *
  57.     * @return all commands
  58.     */
  59.     public function getCommands({
  60.         return $this->commands;
  61.     }
  62.  
  63.     static function getInstance({
  64.         if (is_null(self::$instance)) {
  65.             $class = __CLASS__;
  66.             self::$instance = new $class();
  67.         }
  68.         return self::$instance;
  69.     }
  70. }

Documentation generated on Mon, 11 Mar 2019 14:40:32 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.