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