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

Source for file Extensions.php

Documentation is available at Extensions.php

  1. <?php
  2.  
  3. /**
  4. * the interface for all shell extensions
  5. *
  6. * Extension can hook into the execution of the shell
  7. *
  8. * examples:
  9. * - execution time for parsing and execute
  10. * - colours for the output
  11. * - inline help
  12. *
  13. *  
  14. */
  15. interface PHP_Shell_Extension {
  16.     public function register();
  17. }
  18.  
  19. /**
  20. * storage class for Shell Extensions
  21. *
  22. */
  23. class PHP_Shell_Extensions {
  24.     /**
  25.     * @var PHP_Shell_Extensions 
  26.     */
  27.     static protected $instance;
  28.  
  29.     /**
  30.     * storage for the extension
  31.     *
  32.     * @var array 
  33.     */
  34.     protected $exts = array();
  35.  
  36.     /**
  37.     * the extension object gives access to the register objects
  38.     * through the a simple $exts->name->...
  39.     *
  40.     * @param string registered name of the extension
  41.     * @return PHP_Shell_Extension object handle
  42.     */
  43.     public function __get($key{
  44.         if (!isset($this->exts[$key])) {
  45.             throw new Exception("Extension $s is not known.");
  46.         }
  47.         return $this->exts[$key];
  48.     }
  49.  
  50.     /**
  51.     * register set of extensions
  52.     *
  53.     * @param array set of (name, class-name) pairs
  54.     */
  55.     public function registerExtensions($exts{
  56.         foreach ($exts as $k => $v{
  57.             $this->registerExtension($k$v);
  58.         }
  59.     }
  60.  
  61.     /**
  62.     * register a single extension
  63.     *
  64.     * @param string name of the registered extension
  65.     * @param PHP_Shell_Extension the extension object
  66.     */
  67.     public function registerExtension($kPHP_Shell_Extension $obj{
  68.         $obj->register();
  69.  
  70.         $this->exts[$k$obj;
  71.     }
  72.  
  73.     /**
  74.     * @return object singleton of the class
  75.     */
  76.     static function getInstance({
  77.         if (is_null(self::$instance)) {
  78.             $class = __CLASS__;
  79.             self::$instance = new $class();
  80.         }
  81.         return self::$instance;
  82.     }
  83. }

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