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