Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
Line 2... Line 2...
2
/**
2
/**
3
 * PEAR_Frontend, the singleton-based frontend for user input/output
3
 * PEAR_Frontend, the singleton-based frontend for user input/output
4
 *
4
 *
5
 * PHP versions 4 and 5
5
 * PHP versions 4 and 5
6
 *
6
 *
7
 * LICENSE: This source file is subject to version 3.0 of the PHP license
-
 
8
 * that is available through the world-wide-web at the following URI:
-
 
9
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
-
 
10
 * the PHP License and are unable to obtain it through the web, please
-
 
11
 * send a note to license@php.net so we can mail you a copy immediately.
-
 
12
 *
-
 
13
 * @category   pear
7
 * @category   pear
14
 * @package    PEAR
8
 * @package    PEAR
15
 * @author     Greg Beaver <cellog@php.net>
9
 * @author     Greg Beaver <cellog@php.net>
16
 * @copyright  1997-2006 The PHP Group
10
 * @copyright  1997-2009 The Authors
17
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
11
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
18
 * @version    CVS: $Id: Frontend.php,v 1.9 2006/03/03 13:13:07 pajoye Exp $
-
 
19
 * @link       http://pear.php.net/package/PEAR
12
 * @link       http://pear.php.net/package/PEAR
20
 * @since      File available since Release 1.4.0a1
13
 * @since      File available since Release 1.4.0a1
21
 */
14
 */
Line 22... Line 15...
22
 
15
 
-
 
16
/**
-
 
17
 * Include error handling
-
 
18
 */
-
 
19
//require_once 'PEAR.php';
-
 
20
 
23
/**
21
/**
24
 * Which user interface class is being used.
22
 * Which user interface class is being used.
25
 * @var string class name
23
 * @var string class name
26
 */
24
 */
Line 33... Line 31...
33
$GLOBALS['_PEAR_FRONTEND_SINGLETON'] = null;
31
$GLOBALS['_PEAR_FRONTEND_SINGLETON'] = null;
Line 34... Line 32...
34
 
32
 
35
/**
33
/**
36
 * Singleton-based frontend for PEAR user input/output
34
 * Singleton-based frontend for PEAR user input/output
37
 *
-
 
38
 * Note that frontend classes must implement userConfirm(), and shoul implement
-
 
39
 * displayFatalError() and outputData()
35
 *
40
 * @category   pear
36
 * @category   pear
41
 * @package    PEAR
37
 * @package    PEAR
42
 * @author     Greg Beaver <cellog@php.net>
38
 * @author     Greg Beaver <cellog@php.net>
43
 * @copyright  1997-2006 The PHP Group
39
 * @copyright  1997-2009 The Authors
44
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
40
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
45
 * @version    Release: 1.5.1
41
 * @version    Release: 1.10.1
46
 * @link       http://pear.php.net/package/PEAR
42
 * @link       http://pear.php.net/package/PEAR
47
 * @since      Class available since Release 1.4.0a1
43
 * @since      Class available since Release 1.4.0a1
48
 */
44
 */
49
class PEAR_Frontend extends PEAR
45
class PEAR_Frontend extends PEAR
50
{
46
{
51
    /**
47
    /**
52
     * Retrieve the frontend object
48
     * Retrieve the frontend object
53
     * @return PEAR_Frontend_CLI|PEAR_Frontend_Web|PEAR_Frontend_Gtk
-
 
54
     * @static
49
     * @return PEAR_Frontend_CLI|PEAR_Frontend_Web|PEAR_Frontend_Gtk
55
     */
50
     */
56
    function &singleton($type = null)
51
    public static function &singleton($type = null)
57
    {
52
    {
58
        if ($type === null) {
53
        if ($type === null) {
59
            if (!isset($GLOBALS['_PEAR_FRONTEND_SINGLETON'])) {
54
            if (!isset($GLOBALS['_PEAR_FRONTEND_SINGLETON'])) {
60
                $a = false;
55
                $a = false;
61
                return $a;
56
                return $a;
62
            }
57
            }
63
            return $GLOBALS['_PEAR_FRONTEND_SINGLETON'];
-
 
64
        } else {
-
 
65
            $a = PEAR_Frontend::setFrontendClass($type);
-
 
66
            return $a;
58
            return $GLOBALS['_PEAR_FRONTEND_SINGLETON'];
-
 
59
        }
-
 
60
 
-
 
61
        $a = PEAR_Frontend::setFrontendClass($type);
67
        }
62
        return $a;
Line 68... Line 63...
68
    }
63
    }
69
 
64
 
70
    /**
65
    /**
71
     * Set the frontend class that will be used by calls to {@link singleton()}
66
     * Set the frontend class that will be used by calls to {@link singleton()}
72
     *
67
     *
73
     * Frontends are expected to conform to the PEAR naming standard of
68
     * Frontends are expected to conform to the PEAR naming standard of
74
     * _ => DIRECTORY_SEPARATOR (PEAR_Frontend_CLI is in PEAR/Frontend/CLI.php)
69
     * _ => DIRECTORY_SEPARATOR (PEAR_Frontend_CLI is in PEAR/Frontend/CLI.php)
75
     * @param string $uiclass full class name
-
 
76
     * @return PEAR_Frontend
70
     * @param string $uiclass full class name
77
     * @static
71
     * @return PEAR_Frontend
78
     */
72
     */
79
    function &setFrontendClass($uiclass)
73
    public static function &setFrontendClass($uiclass)
80
    {
74
    {
81
        if (is_object($GLOBALS['_PEAR_FRONTEND_SINGLETON']) &&
75
        if (is_object($GLOBALS['_PEAR_FRONTEND_SINGLETON']) &&
82
              is_a($GLOBALS['_PEAR_FRONTEND_SINGLETON'], $uiclass)) {
76
              is_a($GLOBALS['_PEAR_FRONTEND_SINGLETON'], $uiclass)) {
-
 
77
            return $GLOBALS['_PEAR_FRONTEND_SINGLETON'];
83
            return $GLOBALS['_PEAR_FRONTEND_SINGLETON'];
78
        }
84
        }
79
 
85
        if (!class_exists($uiclass)) {
80
        if (!class_exists($uiclass)) {
86
            $file = str_replace('_', '/', $uiclass) . '.php';
81
            $file = str_replace('_', '/', $uiclass) . '.php';
87
            if (PEAR_Frontend::isIncludeable($file)) {
82
            if (PEAR_Frontend::isIncludeable($file)) {
88
                include_once $file;
83
                include_once $file;
-
 
84
            }
89
            }
85
        }
90
        }
86
 
91
        if (class_exists($uiclass)) {
87
        if (class_exists($uiclass)) {
92
            $obj = &new $uiclass;
88
            $obj = new $uiclass;
93
            // quick test to see if this class implements a few of the most
89
            // quick test to see if this class implements a few of the most
94
            // important frontend methods
90
            // important frontend methods
95
            if (method_exists($obj, 'userConfirm')) {
91
            if (is_a($obj, 'PEAR_Frontend')) {
96
                $GLOBALS['_PEAR_FRONTEND_SINGLETON'] = &$obj;
92
                $GLOBALS['_PEAR_FRONTEND_SINGLETON'] = &$obj;
97
                $GLOBALS['_PEAR_FRONTEND_CLASS'] = $uiclass;
-
 
98
                return $obj;
-
 
99
            } else {
-
 
100
                $err = PEAR::raiseError("not a frontend class: $uiclass");
93
                $GLOBALS['_PEAR_FRONTEND_CLASS'] = $uiclass;
-
 
94
                return $obj;
-
 
95
            }
-
 
96
 
101
                return $err;
97
            $err = PEAR::raiseError("not a frontend class: $uiclass");
-
 
98
            return $err;
102
            }
99
        }
103
        }
100
 
104
        $err = PEAR::raiseError("no such class: $uiclass");
101
        $err = PEAR::raiseError("no such class: $uiclass");
Line 105... Line 102...
105
        return $err;
102
        return $err;
106
    }
103
    }
107
 
104
 
108
    /**
105
    /**
109
     * Set the frontend class that will be used by calls to {@link singleton()}
106
     * Set the frontend class that will be used by calls to {@link singleton()}
110
     *
107
     *
111
     * Frontends are expected to be a descendant of PEAR_Frontend
-
 
112
     * @param PEAR_Frontend
108
     * Frontends are expected to be a descendant of PEAR_Frontend
113
     * @return PEAR_Frontend
109
     * @param PEAR_Frontend
114
     * @static
110
     * @return PEAR_Frontend
115
     */
111
     */
116
    function &setFrontendObject($uiobject)
112
    public static function &setFrontendObject($uiobject)
117
    {
113
    {
118
        if (is_object($GLOBALS['_PEAR_FRONTEND_SINGLETON']) &&
114
        if (is_object($GLOBALS['_PEAR_FRONTEND_SINGLETON']) &&
-
 
115
              is_a($GLOBALS['_PEAR_FRONTEND_SINGLETON'], get_class($uiobject))) {
119
              is_a($GLOBALS['_PEAR_FRONTEND_SINGLETON'], get_class($uiobject))) {
116
            return $GLOBALS['_PEAR_FRONTEND_SINGLETON'];
120
            return $GLOBALS['_PEAR_FRONTEND_SINGLETON'];
117
        }
121
        }
118
 
122
        if (!is_a($uiobject, 'PEAR_Frontend')) {
119
        if (!is_a($uiobject, 'PEAR_Frontend')) {
123
            $err = PEAR::raiseError('not a valid frontend class: (' .
120
            $err = PEAR::raiseError('not a valid frontend class: (' .
124
                get_class($uiobject) . ')');
-
 
125
            return $err;
-
 
126
        }
-
 
-
 
121
                get_class($uiobject) . ')');
127
        // quick test to see if this class implements a few of the most
122
            return $err;
128
        // important frontend methods
123
        }
129
        if (method_exists($uiobject, 'userConfirm')) {
124
 
130
            $GLOBALS['_PEAR_FRONTEND_SINGLETON'] = &$uiobject;
-
 
131
            $GLOBALS['_PEAR_FRONTEND_CLASS'] = get_class($uiobject);
-
 
132
            return $uiobject;
-
 
133
        } else {
-
 
134
            $err = PEAR::raiseError("not a value frontend class: (" . get_class($uiobject)
-
 
135
                . ')');
125
        $GLOBALS['_PEAR_FRONTEND_SINGLETON'] = &$uiobject;
Line 136... Line 126...
136
            return $err;
126
        $GLOBALS['_PEAR_FRONTEND_CLASS'] = get_class($uiobject);
137
        }
127
        return $uiobject;
138
    }
128
    }
139
 
-
 
140
    /**
129
 
141
     * @param string $path relative or absolute include path
130
    /**
142
     * @return boolean
131
     * @param string $path relative or absolute include path
143
     * @static
132
     * @return boolean
144
     */
133
     */
145
    function isIncludeable($path)
134
    public static function isIncludeable($path)
146
    {
-
 
-
 
135
    {
147
        if (file_exists($path) && is_readable($path)) {
136
        if (file_exists($path) && is_readable($path)) {
148
            return true;
-
 
149
        }
-
 
150
        $ipath = explode(PATH_SEPARATOR, ini_get('include_path'));
-
 
151
        foreach ($ipath as $include) {
137
            return true;
152
            $test = realpath($include . DIRECTORY_SEPARATOR . $path);
138
        }
153
            if (!$test) { // support wrappers like phar (realpath just don't work with them)
139
 
154
                $test = $include . DIRECTORY_SEPARATOR . $path;
-
 
155
            }
140
        $fp = @fopen($path, 'r', true);
-
 
141
        if ($fp) {
156
            if (file_exists($test) && is_readable($test)) {
142
            fclose($fp);
157
                return true;
143
            return true;
Line 158... Line 144...
158
            }
144
        }
159
        }
145
 
Line 177... Line 163...
177
    function addTempFile($file)
163
    function addTempFile($file)
178
    {
164
    {
179
        $GLOBALS['_PEAR_Common_tempfiles'][] = $file;
165
        $GLOBALS['_PEAR_Common_tempfiles'][] = $file;
180
    }
166
    }
Line -... Line 167...
-
 
167
 
-
 
168
    /**
-
 
169
     * Log an action
-
 
170
     *
-
 
171
     * @param string $msg the message to log
-
 
172
     * @param boolean $append_crlf
-
 
173
     * @return boolean true
-
 
174
     * @abstract
181
 
175
     */
182
    function log($msg, $append_crlf = true)
176
    function log($msg, $append_crlf = true)
183
    {
177
    {
184
    }
-
 
185
}
-
 
186
?>
178
    }
-
 
179
 
-
 
180
    /**
-
 
181
     * Run a post-installation script
-
 
182
     *
-
 
183
     * @param array $scripts array of post-install scripts
-
 
184
     * @abstract
-
 
185
     */
-
 
186
    function runPostinstallScripts(&$scripts)
-
 
187
    {
-
 
188
    }
-
 
189
 
-
 
190
    /**
-
 
191
     * Display human-friendly output formatted depending on the
-
 
192
     * $command parameter.
-
 
193
     *
-
 
194
     * This should be able to handle basic output data with no command
-
 
195
     * @param mixed  $data    data structure containing the information to display
-
 
196
     * @param string $command command from which this method was called
-
 
197
     * @abstract
-
 
198
     */
-
 
199
    function outputData($data, $command = '_default')
-
 
200
    {
-
 
201
    }
-
 
202
 
-
 
203
    /**
-
 
204
     * Display a modal form dialog and return the given input
-
 
205
     *
-
 
206
     * A frontend that requires multiple requests to retrieve and process
-
 
207
     * data must take these needs into account, and implement the request
-
 
208
     * handling code.
-
 
209
     * @param string $command  command from which this method was called
-
 
210
     * @param array  $prompts  associative array. keys are the input field names
-
 
211
     *                         and values are the description
-
 
212
     * @param array  $types    array of input field types (text, password,
-
 
213
     *                         etc.) keys have to be the same like in $prompts
-
 
214
     * @param array  $defaults array of default values. again keys have
-
 
215
     *                         to be the same like in $prompts.  Do not depend
-
 
216
     *                         on a default value being set.
-
 
217
     * @return array input sent by the user
-
 
218
     * @abstract
-
 
219
     */
-
 
220
    function userDialog($command, $prompts, $types = array(), $defaults = array())
-
 
221
    {
-
 
222
    }
-
 
223
}
187
224