Редакция 69 | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
69 | alex-w | 1 | <?php |
2 | /** |
||
3 | * PEAR_Frontend, the singleton-based frontend for user input/output |
||
4 | * |
||
5 | * PHP versions 4 and 5 |
||
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 |
||
14 | * @package PEAR |
||
15 | * @author Greg Beaver <cellog@php.net> |
||
16 | * @copyright 1997-2008 The PHP Group |
||
17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 |
||
18 | * @version CVS: $Id: Frontend.php,v 1.13 2008/01/03 20:26:35 cellog Exp $ |
||
19 | * @link http://pear.php.net/package/PEAR |
||
20 | * @since File available since Release 1.4.0a1 |
||
21 | */ |
||
22 | |||
23 | /** |
||
24 | * Which user interface class is being used. |
||
25 | * @var string class name |
||
26 | */ |
||
27 | $GLOBALS['_PEAR_FRONTEND_CLASS'] = 'PEAR_Frontend_CLI'; |
||
28 | |||
29 | /** |
||
30 | * Instance of $_PEAR_Command_uiclass. |
||
31 | * @var object |
||
32 | */ |
||
33 | $GLOBALS['_PEAR_FRONTEND_SINGLETON'] = null; |
||
34 | |||
35 | /** |
||
36 | * Singleton-based frontend for PEAR user input/output |
||
37 | * |
||
38 | * @category pear |
||
39 | * @package PEAR |
||
40 | * @author Greg Beaver <cellog@php.net> |
||
41 | * @copyright 1997-2008 The PHP Group |
||
42 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 |
||
43 | * @version Release: 1.7.2 |
||
44 | * @link http://pear.php.net/package/PEAR |
||
45 | * @since Class available since Release 1.4.0a1 |
||
46 | */ |
||
47 | class PEAR_Frontend extends PEAR |
||
48 | { |
||
49 | /** |
||
50 | * Retrieve the frontend object |
||
51 | * @return PEAR_Frontend_CLI|PEAR_Frontend_Web|PEAR_Frontend_Gtk |
||
52 | * @static |
||
53 | */ |
||
54 | function &singleton($type = null) |
||
55 | { |
||
56 | if ($type === null) { |
||
57 | if (!isset($GLOBALS['_PEAR_FRONTEND_SINGLETON'])) { |
||
58 | $a = false; |
||
59 | return $a; |
||
60 | } |
||
61 | return $GLOBALS['_PEAR_FRONTEND_SINGLETON']; |
||
62 | } else { |
||
63 | $a = PEAR_Frontend::setFrontendClass($type); |
||
64 | return $a; |
||
65 | } |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Set the frontend class that will be used by calls to {@link singleton()} |
||
70 | * |
||
71 | * Frontends are expected to conform to the PEAR naming standard of |
||
72 | * _ => DIRECTORY_SEPARATOR (PEAR_Frontend_CLI is in PEAR/Frontend/CLI.php) |
||
73 | * @param string $uiclass full class name |
||
74 | * @return PEAR_Frontend |
||
75 | * @static |
||
76 | */ |
||
77 | function &setFrontendClass($uiclass) |
||
78 | { |
||
79 | if (is_object($GLOBALS['_PEAR_FRONTEND_SINGLETON']) && |
||
80 | is_a($GLOBALS['_PEAR_FRONTEND_SINGLETON'], $uiclass)) { |
||
81 | return $GLOBALS['_PEAR_FRONTEND_SINGLETON']; |
||
82 | } |
||
83 | if (!class_exists($uiclass)) { |
||
84 | $file = str_replace('_', '/', $uiclass) . '.php'; |
||
85 | if (PEAR_Frontend::isIncludeable($file)) { |
||
86 | include_once $file; |
||
87 | } |
||
88 | } |
||
89 | if (class_exists($uiclass)) { |
||
90 | $obj = &new $uiclass; |
||
91 | // quick test to see if this class implements a few of the most |
||
92 | // important frontend methods |
||
93 | if (is_a($obj, 'PEAR_Frontend')) { |
||
94 | $GLOBALS['_PEAR_FRONTEND_SINGLETON'] = &$obj; |
||
95 | $GLOBALS['_PEAR_FRONTEND_CLASS'] = $uiclass; |
||
96 | return $obj; |
||
97 | } else { |
||
98 | $err = PEAR::raiseError("not a frontend class: $uiclass"); |
||
99 | return $err; |
||
100 | } |
||
101 | } |
||
102 | $err = PEAR::raiseError("no such class: $uiclass"); |
||
103 | return $err; |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Set the frontend class that will be used by calls to {@link singleton()} |
||
108 | * |
||
109 | * Frontends are expected to be a descendant of PEAR_Frontend |
||
110 | * @param PEAR_Frontend |
||
111 | * @return PEAR_Frontend |
||
112 | * @static |
||
113 | */ |
||
114 | function &setFrontendObject($uiobject) |
||
115 | { |
||
116 | if (is_object($GLOBALS['_PEAR_FRONTEND_SINGLETON']) && |
||
117 | is_a($GLOBALS['_PEAR_FRONTEND_SINGLETON'], get_class($uiobject))) { |
||
118 | return $GLOBALS['_PEAR_FRONTEND_SINGLETON']; |
||
119 | } |
||
120 | if (!is_a($uiobject, 'PEAR_Frontend')) { |
||
121 | $err = PEAR::raiseError('not a valid frontend class: (' . |
||
122 | get_class($uiobject) . ')'); |
||
123 | return $err; |
||
124 | } |
||
125 | $GLOBALS['_PEAR_FRONTEND_SINGLETON'] = &$uiobject; |
||
126 | $GLOBALS['_PEAR_FRONTEND_CLASS'] = get_class($uiobject); |
||
127 | return $uiobject; |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * @param string $path relative or absolute include path |
||
132 | * @return boolean |
||
133 | * @static |
||
134 | */ |
||
135 | function isIncludeable($path) |
||
136 | { |
||
137 | if (file_exists($path) && is_readable($path)) { |
||
138 | return true; |
||
139 | } |
||
140 | $fp = @fopen($path, 'r', true); |
||
141 | if ($fp) { |
||
142 | fclose($fp); |
||
143 | return true; |
||
144 | } |
||
145 | return false; |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * @param PEAR_Config |
||
150 | */ |
||
151 | function setConfig(&$config) |
||
152 | { |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * This can be overridden to allow session-based temporary file management |
||
157 | * |
||
158 | * By default, all files are deleted at the end of a session. The web installer |
||
159 | * needs to be able to sustain a list over many sessions in order to support |
||
160 | * user interaction with install scripts |
||
161 | */ |
||
162 | function addTempFile($file) |
||
163 | { |
||
164 | $GLOBALS['_PEAR_Common_tempfiles'][] = $file; |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * Log an action |
||
169 | * |
||
170 | * @param string $msg the message to log |
||
171 | * @param boolean $append_crlf |
||
172 | * @return boolean true |
||
173 | * @abstract |
||
174 | */ |
||
175 | function log($msg, $append_crlf = true) |
||
176 | { |
||
177 | } |
||
178 | |||
179 | /** |
||
180 | * Run a post-installation script |
||
181 | * |
||
182 | * @param array $scripts array of post-install scripts |
||
183 | * @abstract |
||
184 | */ |
||
185 | function runPostinstallScripts(&$scripts) |
||
186 | { |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * Display human-friendly output formatted depending on the |
||
191 | * $command parameter. |
||
192 | * |
||
193 | * This should be able to handle basic output data with no command |
||
194 | * @param mixed $data data structure containing the information to display |
||
195 | * @param string $command command from which this method was called |
||
196 | * @abstract |
||
197 | */ |
||
198 | function outputData($data, $command = '_default') |
||
199 | { |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * Display a modal form dialog and return the given input |
||
204 | * |
||
205 | * A frontend that requires multiple requests to retrieve and process |
||
206 | * data must take these needs into account, and implement the request |
||
207 | * handling code. |
||
208 | * @param string $command command from which this method was called |
||
209 | * @param array $prompts associative array. keys are the input field names |
||
210 | * and values are the description |
||
211 | * @param array $types array of input field types (text, password, |
||
212 | * etc.) keys have to be the same like in $prompts |
||
213 | * @param array $defaults array of default values. again keys have |
||
214 | * to be the same like in $prompts. Do not depend |
||
215 | * on a default value being set. |
||
216 | * @return array input sent by the user |
||
217 | * @abstract |
||
218 | */ |
||
219 | function userDialog($command, $prompts, $types = array(), $defaults = array()) |
||
220 | { |
||
221 | } |
||
222 | } |
||
223 | ?> |