Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 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
*/
24
class PHP_Shell_Extensions {
25
    /**
26
    * @var PHP_Shell_Extensions
27
    */
28
    static protected $instance;
29
 
30
    /**
31
    * storage for the extension
32
    *
33
    * @var array
34
    */
35
    protected $exts = array();
36
 
37
    /**
38
    * the extension object gives access to the register objects
39
    * through the a simple $exts->name->...
40
    *
41
    * @param string registered name of the extension
42
    * @return PHP_Shell_Extension object handle
43
    */
44
    public function __get($key) {
45
        if (!isset($this->exts[$key])) {
46
            throw new Exception("Extension $s is not known.");
47
        }
48
        return $this->exts[$key];
49
    }
50
 
51
    /**
52
    * register set of extensions
53
    *
54
    * @param array set of (name, class-name) pairs
55
    */
56
    public function registerExtensions($exts) {
57
        foreach ($exts as $k => $v) {
58
            $this->registerExtension($k, $v);
59
        }
60
    }
61
 
62
    /**
63
    * register a single extension
64
    *
65
    * @param string name of the registered extension
66
    * @param PHP_Shell_Extension the extension object
67
    */
68
    public function registerExtension($k, PHP_Shell_Extension $obj) {
69
        $obj->register();
70
 
71
        $this->exts[$k] = $obj;
72
    }
73
 
74
    /**
75
    * @return object a singleton of the class
76
    */
77
    static function getInstance() {
78
        if (is_null(self::$instance)) {
79
            $class = __CLASS__;
80
            self::$instance = new $class();
81
        }
82
        return self::$instance;
83
    }
84
}
85
 
86