Редакция 69 | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 69 | Редакция 94 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | /**
|
2 | /**
|
3 | * PEAR_Command, command pattern class
|
3 | * PEAR_Command, command pattern class
|
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 Stig Bakken <ssb@php.net>
|
15 | * @author Stig Bakken <ssb@php.net>
|
16 | * @author Greg Beaver <cellog@php.net>
|
16 | * @author Greg Beaver <cellog@php.net>
|
17 | * @copyright 1997-2008 The PHP Group
|
17 | * @copyright 1997-2008 The PHP Group
|
18 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
18 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
19 | * @version CVS: $Id: Command.php,v 1.39 2008/01/03 20:26:34 cellog Exp $
|
19 | * @version CVS: $Id: Command.php,v 1.39 2008/01/03 20:26:34 cellog Exp $
|
20 | * @link http://pear.php.net/package/PEAR
|
20 | * @link http://pear.php.net/package/PEAR
|
21 | * @since File available since Release 0.1
|
21 | * @since File available since Release 0.1
|
22 | */
|
22 | */
|
23 | 23 | ||
24 | /**
|
24 | /**
|
25 | * Needed for error handling
|
25 | * Needed for error handling
|
26 | */
|
26 | */
|
27 | require_once 'PEAR.php'; |
27 | require_once 'PEAR.php'; |
28 | require_once 'PEAR/Frontend.php'; |
28 | require_once 'PEAR/Frontend.php'; |
29 | require_once 'PEAR/XMLParser.php'; |
29 | require_once 'PEAR/XMLParser.php'; |
30 | 30 | ||
31 | /**
|
31 | /**
|
32 | * List of commands and what classes they are implemented in.
|
32 | * List of commands and what classes they are implemented in.
|
33 | * @var array command => implementing class
|
33 | * @var array command => implementing class
|
34 | */
|
34 | */
|
35 | $GLOBALS['_PEAR_Command_commandlist'] = array(); |
35 | $GLOBALS['_PEAR_Command_commandlist'] = array(); |
36 | 36 | ||
37 | /**
|
37 | /**
|
38 | * List of commands and their descriptions
|
38 | * List of commands and their descriptions
|
39 | * @var array command => description
|
39 | * @var array command => description
|
40 | */
|
40 | */
|
41 | $GLOBALS['_PEAR_Command_commanddesc'] = array(); |
41 | $GLOBALS['_PEAR_Command_commanddesc'] = array(); |
42 | 42 | ||
43 | /**
|
43 | /**
|
44 | * List of shortcuts to common commands.
|
44 | * List of shortcuts to common commands.
|
45 | * @var array shortcut => command
|
45 | * @var array shortcut => command
|
46 | */
|
46 | */
|
47 | $GLOBALS['_PEAR_Command_shortcuts'] = array(); |
47 | $GLOBALS['_PEAR_Command_shortcuts'] = array(); |
48 | 48 | ||
49 | /**
|
49 | /**
|
50 | * Array of command objects
|
50 | * Array of command objects
|
51 | * @var array class => object
|
51 | * @var array class => object
|
52 | */
|
52 | */
|
53 | $GLOBALS['_PEAR_Command_objects'] = array(); |
53 | $GLOBALS['_PEAR_Command_objects'] = array(); |
54 | 54 | ||
55 | /**
|
55 | /**
|
56 | * PEAR command class, a simple factory class for administrative
|
56 | * PEAR command class, a simple factory class for administrative
|
57 | * commands.
|
57 | * commands.
|
58 | *
|
58 | *
|
59 | * How to implement command classes:
|
59 | * How to implement command classes:
|
60 | *
|
60 | *
|
61 | * - The class must be called PEAR_Command_Nnn, installed in the
|
61 | * - The class must be called PEAR_Command_Nnn, installed in the
|
62 | * "PEAR/Common" subdir, with a method called getCommands() that
|
62 | * "PEAR/Common" subdir, with a method called getCommands() that
|
63 | * returns an array of the commands implemented by the class (see
|
63 | * returns an array of the commands implemented by the class (see
|
64 | * PEAR/Command/Install.php for an example).
|
64 | * PEAR/Command/Install.php for an example).
|
65 | *
|
65 | *
|
66 | * - The class must implement a run() function that is called with three
|
66 | * - The class must implement a run() function that is called with three
|
67 | * params:
|
67 | * params:
|
68 | *
|
68 | *
|
69 | * (string) command name
|
69 | * (string) command name
|
70 | * (array) assoc array with options, freely defined by each
|
70 | * (array) assoc array with options, freely defined by each
|
71 | * command, for example:
|
71 | * command, for example:
|
72 | * array('force' => true)
|
72 | * array('force' => true)
|
73 | * (array) list of the other parameters
|
73 | * (array) list of the other parameters
|
74 | *
|
74 | *
|
75 | * The run() function returns a PEAR_CommandResponse object. Use
|
75 | * The run() function returns a PEAR_CommandResponse object. Use
|
76 | * these methods to get information:
|
76 | * these methods to get information:
|
77 | *
|
77 | *
|
78 | * int getStatus() Returns PEAR_COMMAND_(SUCCESS|FAILURE|PARTIAL)
|
78 | * int getStatus() Returns PEAR_COMMAND_(SUCCESS|FAILURE|PARTIAL)
|
79 | * *_PARTIAL means that you need to issue at least
|
79 | * *_PARTIAL means that you need to issue at least
|
80 | * one more command to complete the operation
|
80 | * one more command to complete the operation
|
81 | * (used for example for validation steps).
|
81 | * (used for example for validation steps).
|
82 | *
|
82 | *
|
83 | * string getMessage() Returns a message for the user. Remember,
|
83 | * string getMessage() Returns a message for the user. Remember,
|
84 | * no HTML or other interface-specific markup.
|
84 | * no HTML or other interface-specific markup.
|
85 | *
|
85 | *
|
86 | * If something unexpected happens, run() returns a PEAR error.
|
86 | * If something unexpected happens, run() returns a PEAR error.
|
87 | *
|
87 | *
|
88 | * - DON'T OUTPUT ANYTHING! Return text for output instead.
|
88 | * - DON'T OUTPUT ANYTHING! Return text for output instead.
|
89 | *
|
89 | *
|
90 | * - DON'T USE HTML! The text you return will be used from both Gtk,
|
90 | * - DON'T USE HTML! The text you return will be used from both Gtk,
|
91 | * web and command-line interfaces, so for now, keep everything to
|
91 | * web and command-line interfaces, so for now, keep everything to
|
92 | * plain text.
|
92 | * plain text.
|
93 | *
|
93 | *
|
94 | * - DON'T USE EXIT OR DIE! Always use pear errors. From static
|
94 | * - DON'T USE EXIT OR DIE! Always use pear errors. From static
|
95 | * classes do PEAR::raiseError(), from other classes do
|
95 | * classes do PEAR::raiseError(), from other classes do
|
96 | * $this->raiseError().
|
96 | * $this->raiseError().
|
97 | * @category pear
|
97 | * @category pear
|
98 | * @package PEAR
|
98 | * @package PEAR
|
99 | * @author Stig Bakken <ssb@php.net>
|
99 | * @author Stig Bakken <ssb@php.net>
|
100 | * @author Greg Beaver <cellog@php.net>
|
100 | * @author Greg Beaver <cellog@php.net>
|
101 | * @copyright 1997-2008 The PHP Group
|
101 | * @copyright 1997-2008 The PHP Group
|
102 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
102 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
103 | * @version Release: 1.7.2
|
103 | * @version Release: 1.7.2
|
104 | * @link http://pear.php.net/package/PEAR
|
104 | * @link http://pear.php.net/package/PEAR
|
105 | * @since Class available since Release 0.1
|
105 | * @since Class available since Release 0.1
|
106 | */
|
106 | */
|
107 | class PEAR_Command
|
107 | class PEAR_Command
|
108 | {
|
108 | {
|
109 | // {{{ factory()
|
109 | // {{{ factory()
|
110 | 110 | ||
111 | /**
|
111 | /**
|
112 | * Get the right object for executing a command.
|
112 | * Get the right object for executing a command.
|
113 | *
|
113 | *
|
114 | * @param string $command The name of the command
|
114 | * @param string $command The name of the command
|
115 | * @param object $config Instance of PEAR_Config object
|
115 | * @param object $config Instance of PEAR_Config object
|
116 | *
|
116 | *
|
117 | * @return object the command object or a PEAR error
|
117 | * @return object the command object or a PEAR error
|
118 | *
|
118 | *
|
119 | * @access public
|
119 | * @access public
|
120 | * @static
|
120 | * @static
|
121 | */
|
121 | */
|
122 | function &factory($command, &$config) |
122 | function &factory($command, &$config) |
123 | {
|
123 | {
|
124 | if (empty($GLOBALS['_PEAR_Command_commandlist'])) { |
124 | if (empty($GLOBALS['_PEAR_Command_commandlist'])) { |
125 | PEAR_Command::registerCommands(); |
125 | PEAR_Command::registerCommands(); |
126 | }
|
126 | }
|
127 | if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) { |
127 | if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) { |
128 | $command = $GLOBALS['_PEAR_Command_shortcuts'][$command]; |
128 | $command = $GLOBALS['_PEAR_Command_shortcuts'][$command]; |
129 | }
|
129 | }
|
130 | if (!isset($GLOBALS['_PEAR_Command_commandlist'][$command])) { |
130 | if (!isset($GLOBALS['_PEAR_Command_commandlist'][$command])) { |
131 | $a = PEAR::raiseError("unknown command `$command'"); |
131 | $a = PEAR::raiseError("unknown command `$command'"); |
132 | return $a; |
132 | return $a; |
133 | }
|
133 | }
|
134 | $class = $GLOBALS['_PEAR_Command_commandlist'][$command]; |
134 | $class = $GLOBALS['_PEAR_Command_commandlist'][$command]; |
135 | if (!class_exists($class)) { |
135 | if (!class_exists($class)) { |
136 | require_once $GLOBALS['_PEAR_Command_objects'][$class]; |
136 | require_once $GLOBALS['_PEAR_Command_objects'][$class]; |
137 | }
|
137 | }
|
138 | if (!class_exists($class)) { |
138 | if (!class_exists($class)) { |
139 | $a = PEAR::raiseError("unknown command `$command'"); |
139 | $a = PEAR::raiseError("unknown command `$command'"); |
140 | return $a; |
140 | return $a; |
141 | }
|
141 | }
|
142 | $ui =& PEAR_Command::getFrontendObject(); |
142 | $ui =& PEAR_Command::getFrontendObject(); |
143 | $obj = &new $class($ui, $config); |
143 | $obj = &new $class($ui, $config); |
144 | return $obj; |
144 | return $obj; |
145 | }
|
145 | }
|
146 | 146 | ||
147 | // }}}
|
147 | // }}}
|
148 | // {{{ & getObject()
|
148 | // {{{ & getObject()
|
149 | function &getObject($command) |
149 | function &getObject($command) |
150 | {
|
150 | {
|
151 | $class = $GLOBALS['_PEAR_Command_commandlist'][$command]; |
151 | $class = $GLOBALS['_PEAR_Command_commandlist'][$command]; |
152 | if (!class_exists($class)) { |
152 | if (!class_exists($class)) { |
153 | require_once $GLOBALS['_PEAR_Command_objects'][$class]; |
153 | require_once $GLOBALS['_PEAR_Command_objects'][$class]; |
154 | }
|
154 | }
|
155 | if (!class_exists($class)) { |
155 | if (!class_exists($class)) { |
156 | return PEAR::raiseError("unknown command `$command'"); |
156 | return PEAR::raiseError("unknown command `$command'"); |
157 | }
|
157 | }
|
158 | $ui =& PEAR_Command::getFrontendObject(); |
158 | $ui =& PEAR_Command::getFrontendObject(); |
159 | $config = &PEAR_Config::singleton(); |
159 | $config = &PEAR_Config::singleton(); |
160 | $obj = &new $class($ui, $config); |
160 | $obj = &new $class($ui, $config); |
161 | return $obj; |
161 | return $obj; |
162 | }
|
162 | }
|
163 | 163 | ||
164 | // }}}
|
164 | // }}}
|
165 | // {{{ & getFrontendObject()
|
165 | // {{{ & getFrontendObject()
|
166 | 166 | ||
167 | /**
|
167 | /**
|
168 | * Get instance of frontend object.
|
168 | * Get instance of frontend object.
|
169 | *
|
169 | *
|
170 | * @return object|PEAR_Error
|
170 | * @return object|PEAR_Error
|
171 | * @static
|
171 | * @static
|
172 | */
|
172 | */
|
173 | function &getFrontendObject() |
173 | function &getFrontendObject() |
174 | {
|
174 | {
|
175 | $a = &PEAR_Frontend::singleton(); |
175 | $a = &PEAR_Frontend::singleton(); |
176 | return $a; |
176 | return $a; |
177 | }
|
177 | }
|
178 | 178 | ||
179 | // }}}
|
179 | // }}}
|
180 | // {{{ & setFrontendClass()
|
180 | // {{{ & setFrontendClass()
|
181 | 181 | ||
182 | /**
|
182 | /**
|
183 | * Load current frontend class.
|
183 | * Load current frontend class.
|
184 | *
|
184 | *
|
185 | * @param string $uiclass Name of class implementing the frontend
|
185 | * @param string $uiclass Name of class implementing the frontend
|
186 | *
|
186 | *
|
187 | * @return object the frontend object, or a PEAR error
|
187 | * @return object the frontend object, or a PEAR error
|
188 | * @static
|
188 | * @static
|
189 | */
|
189 | */
|
190 | function &setFrontendClass($uiclass) |
190 | function &setFrontendClass($uiclass) |
191 | {
|
191 | {
|
192 | $a = &PEAR_Frontend::setFrontendClass($uiclass); |
192 | $a = &PEAR_Frontend::setFrontendClass($uiclass); |
193 | return $a; |
193 | return $a; |
194 | }
|
194 | }
|
195 | 195 | ||
196 | // }}}
|
196 | // }}}
|
197 | // {{{ setFrontendType()
|
197 | // {{{ setFrontendType()
|
198 | 198 | ||
199 | /**
|
199 | /**
|
200 | * Set current frontend.
|
200 | * Set current frontend.
|
201 | *
|
201 | *
|
202 | * @param string $uitype Name of the frontend type (for example "CLI")
|
202 | * @param string $uitype Name of the frontend type (for example "CLI")
|
203 | *
|
203 | *
|
204 | * @return object the frontend object, or a PEAR error
|
204 | * @return object the frontend object, or a PEAR error
|
205 | * @static
|
205 | * @static
|
206 | */
|
206 | */
|
207 | function setFrontendType($uitype) |
207 | function setFrontendType($uitype) |
208 | {
|
208 | {
|
209 | $uiclass = 'PEAR_Frontend_' . $uitype; |
209 | $uiclass = 'PEAR_Frontend_' . $uitype; |
210 | return PEAR_Command::setFrontendClass($uiclass); |
210 | return PEAR_Command::setFrontendClass($uiclass); |
211 | }
|
211 | }
|
212 | 212 | ||
213 | // }}}
|
213 | // }}}
|
214 | // {{{ registerCommands()
|
214 | // {{{ registerCommands()
|
215 | 215 | ||
216 | /**
|
216 | /**
|
217 | * Scan through the Command directory looking for classes
|
217 | * Scan through the Command directory looking for classes
|
218 | * and see what commands they implement.
|
218 | * and see what commands they implement.
|
219 | *
|
219 | *
|
220 | * @param bool (optional) if FALSE (default), the new list of
|
220 | * @param bool (optional) if FALSE (default), the new list of
|
221 | * commands should replace the current one. If TRUE,
|
221 | * commands should replace the current one. If TRUE,
|
222 | * new entries will be merged with old.
|
222 | * new entries will be merged with old.
|
223 | *
|
223 | *
|
224 | * @param string (optional) where (what directory) to look for
|
224 | * @param string (optional) where (what directory) to look for
|
225 | * classes, defaults to the Command subdirectory of
|
225 | * classes, defaults to the Command subdirectory of
|
226 | * the directory from where this file (__FILE__) is
|
226 | * the directory from where this file (__FILE__) is
|
227 | * included.
|
227 | * included.
|
228 | *
|
228 | *
|
229 | * @return bool TRUE on success, a PEAR error on failure
|
229 | * @return bool TRUE on success, a PEAR error on failure
|
230 | *
|
230 | *
|
231 | * @access public
|
231 | * @access public
|
232 | * @static
|
232 | * @static
|
233 | */
|
233 | */
|
234 | function registerCommands($merge = false, $dir = null) |
234 | function registerCommands($merge = false, $dir = null) |
235 | {
|
235 | {
|
236 | $parser = new PEAR_XMLParser; |
236 | $parser = new PEAR_XMLParser; |
237 | if ($dir === null) { |
237 | if ($dir === null) { |
238 | $dir = dirname(__FILE__) . '/Command'; |
238 | $dir = dirname(__FILE__) . '/Command'; |
239 | }
|
239 | }
|
240 | if (!is_dir($dir)) { |
240 | if (!is_dir($dir)) { |
241 | return PEAR::raiseError("registerCommands: opendir($dir) '$dir' does not exist or is not a directory"); |
241 | return PEAR::raiseError("registerCommands: opendir($dir) '$dir' does not exist or is not a directory"); |
242 | }
|
242 | }
|
243 | $dp = @opendir($dir); |
243 | $dp = @opendir($dir); |
244 | if (empty($dp)) { |
244 | if (empty($dp)) { |
245 | return PEAR::raiseError("registerCommands: opendir($dir) failed"); |
245 | return PEAR::raiseError("registerCommands: opendir($dir) failed"); |
246 | }
|
246 | }
|
247 | if (!$merge) { |
247 | if (!$merge) { |
248 | $GLOBALS['_PEAR_Command_commandlist'] = array(); |
248 | $GLOBALS['_PEAR_Command_commandlist'] = array(); |
249 | }
|
249 | }
|
250 | while ($entry = readdir($dp)) { |
250 | while ($entry = readdir($dp)) { |
251 | if ($entry{0} == '.' || substr($entry, -4) != '.xml') { |
251 | if ($entry{0} == '.' || substr($entry, -4) != '.xml') { |
252 | continue; |
252 | continue; |
253 | }
|
253 | }
|
254 | $class = "PEAR_Command_".substr($entry, 0, -4); |
254 | $class = "PEAR_Command_".substr($entry, 0, -4); |
255 | $file = "$dir/$entry"; |
255 | $file = "$dir/$entry"; |
256 | $parser->parse(file_get_contents($file)); |
256 | $parser->parse(file_get_contents($file)); |
257 | $implements = $parser->getData(); |
257 | $implements = $parser->getData(); |
258 | // List of commands
|
258 | // List of commands
|
259 | if (empty($GLOBALS['_PEAR_Command_objects'][$class])) { |
259 | if (empty($GLOBALS['_PEAR_Command_objects'][$class])) { |
260 | $GLOBALS['_PEAR_Command_objects'][$class] = "$dir/" . substr($entry, 0, -4) . |
260 | $GLOBALS['_PEAR_Command_objects'][$class] = "$dir/" . substr($entry, 0, -4) . |
261 | '.php'; |
261 | '.php'; |
262 | }
|
262 | }
|
263 | foreach ($implements as $command => $desc) { |
263 | foreach ($implements as $command => $desc) { |
264 | if ($command == 'attribs') { |
264 | if ($command == 'attribs') { |
265 | continue; |
265 | continue; |
266 | }
|
266 | }
|
267 | if (isset($GLOBALS['_PEAR_Command_commandlist'][$command])) { |
267 | if (isset($GLOBALS['_PEAR_Command_commandlist'][$command])) { |
268 | return PEAR::raiseError('Command "' . $command . '" already registered in ' . |
268 | return PEAR::raiseError('Command "' . $command . '" already registered in ' . |
269 | 'class "' . $GLOBALS['_PEAR_Command_commandlist'][$command] . '"'); |
269 | 'class "' . $GLOBALS['_PEAR_Command_commandlist'][$command] . '"'); |
270 | }
|
270 | }
|
271 | $GLOBALS['_PEAR_Command_commandlist'][$command] = $class; |
271 | $GLOBALS['_PEAR_Command_commandlist'][$command] = $class; |
272 | $GLOBALS['_PEAR_Command_commanddesc'][$command] = $desc['summary']; |
272 | $GLOBALS['_PEAR_Command_commanddesc'][$command] = $desc['summary']; |
273 | if (isset($desc['shortcut'])) { |
273 | if (isset($desc['shortcut'])) { |
274 | $shortcut = $desc['shortcut']; |
274 | $shortcut = $desc['shortcut']; |
275 | if (isset($GLOBALS['_PEAR_Command_shortcuts'][$shortcut])) { |
275 | if (isset($GLOBALS['_PEAR_Command_shortcuts'][$shortcut])) { |
276 | return PEAR::raiseError('Command shortcut "' . $shortcut . '" already ' . |
276 | return PEAR::raiseError('Command shortcut "' . $shortcut . '" already ' . |
277 | 'registered to command "' . $command . '" in class "' . |
277 | 'registered to command "' . $command . '" in class "' . |
278 | $GLOBALS['_PEAR_Command_commandlist'][$command] . '"'); |
278 | $GLOBALS['_PEAR_Command_commandlist'][$command] . '"'); |
279 | }
|
279 | }
|
280 | $GLOBALS['_PEAR_Command_shortcuts'][$shortcut] = $command; |
280 | $GLOBALS['_PEAR_Command_shortcuts'][$shortcut] = $command; |
281 | }
|
281 | }
|
282 | if (isset($desc['options']) && $desc['options']) { |
282 | if (isset($desc['options']) && $desc['options']) { |
283 | foreach ($desc['options'] as $oname => $option) { |
283 | foreach ($desc['options'] as $oname => $option) { |
284 | if (isset($option['shortopt']) && strlen($option['shortopt']) > 1) { |
284 | if (isset($option['shortopt']) && strlen($option['shortopt']) > 1) { |
285 | return PEAR::raiseError('Option "' . $oname . '" short option "' . |
285 | return PEAR::raiseError('Option "' . $oname . '" short option "' . |
286 | $option['shortopt'] . '" must be ' . |
286 | $option['shortopt'] . '" must be ' . |
287 | 'only 1 character in Command "' . $command . '" in class "' . |
287 | 'only 1 character in Command "' . $command . '" in class "' . |
288 | $class . '"'); |
288 | $class . '"'); |
289 | }
|
289 | }
|
290 | }
|
290 | }
|
291 | }
|
291 | }
|
292 | }
|
292 | }
|
293 | }
|
293 | }
|
294 | ksort($GLOBALS['_PEAR_Command_shortcuts']); |
294 | ksort($GLOBALS['_PEAR_Command_shortcuts']); |
295 | ksort($GLOBALS['_PEAR_Command_commandlist']); |
295 | ksort($GLOBALS['_PEAR_Command_commandlist']); |
296 | @closedir($dp); |
296 | @closedir($dp); |
297 | return true; |
297 | return true; |
298 | }
|
298 | }
|
299 | 299 | ||
300 | // }}}
|
300 | // }}}
|
301 | // {{{ getCommands()
|
301 | // {{{ getCommands()
|
302 | 302 | ||
303 | /**
|
303 | /**
|
304 | * Get the list of currently supported commands, and what
|
304 | * Get the list of currently supported commands, and what
|
305 | * classes implement them.
|
305 | * classes implement them.
|
306 | *
|
306 | *
|
307 | * @return array command => implementing class
|
307 | * @return array command => implementing class
|
308 | *
|
308 | *
|
309 | * @access public
|
309 | * @access public
|
310 | * @static
|
310 | * @static
|
311 | */
|
311 | */
|
312 | function getCommands() |
312 | function getCommands() |
313 | {
|
313 | {
|
314 | if (empty($GLOBALS['_PEAR_Command_commandlist'])) { |
314 | if (empty($GLOBALS['_PEAR_Command_commandlist'])) { |
315 | PEAR_Command::registerCommands(); |
315 | PEAR_Command::registerCommands(); |
316 | }
|
316 | }
|
317 | return $GLOBALS['_PEAR_Command_commandlist']; |
317 | return $GLOBALS['_PEAR_Command_commandlist']; |
318 | }
|
318 | }
|
319 | 319 | ||
320 | // }}}
|
320 | // }}}
|
321 | // {{{ getShortcuts()
|
321 | // {{{ getShortcuts()
|
322 | 322 | ||
323 | /**
|
323 | /**
|
324 | * Get the list of command shortcuts.
|
324 | * Get the list of command shortcuts.
|
325 | *
|
325 | *
|
326 | * @return array shortcut => command
|
326 | * @return array shortcut => command
|
327 | *
|
327 | *
|
328 | * @access public
|
328 | * @access public
|
329 | * @static
|
329 | * @static
|
330 | */
|
330 | */
|
331 | function getShortcuts() |
331 | function getShortcuts() |
332 | {
|
332 | {
|
333 | if (empty($GLOBALS['_PEAR_Command_shortcuts'])) { |
333 | if (empty($GLOBALS['_PEAR_Command_shortcuts'])) { |
334 | PEAR_Command::registerCommands(); |
334 | PEAR_Command::registerCommands(); |
335 | }
|
335 | }
|
336 | return $GLOBALS['_PEAR_Command_shortcuts']; |
336 | return $GLOBALS['_PEAR_Command_shortcuts']; |
337 | }
|
337 | }
|
338 | 338 | ||
339 | // }}}
|
339 | // }}}
|
340 | // {{{ getGetoptArgs()
|
340 | // {{{ getGetoptArgs()
|
341 | 341 | ||
342 | /**
|
342 | /**
|
343 | * Compiles arguments for getopt.
|
343 | * Compiles arguments for getopt.
|
344 | *
|
344 | *
|
345 | * @param string $command command to get optstring for
|
345 | * @param string $command command to get optstring for
|
346 | * @param string $short_args (reference) short getopt format
|
346 | * @param string $short_args (reference) short getopt format
|
347 | * @param array $long_args (reference) long getopt format
|
347 | * @param array $long_args (reference) long getopt format
|
348 | *
|
348 | *
|
349 | * @return void
|
349 | * @return void
|
350 | *
|
350 | *
|
351 | * @access public
|
351 | * @access public
|
352 | * @static
|
352 | * @static
|
353 | */
|
353 | */
|
354 | function getGetoptArgs($command, &$short_args, &$long_args) |
354 | function getGetoptArgs($command, &$short_args, &$long_args) |
355 | {
|
355 | {
|
356 | if (empty($GLOBALS['_PEAR_Command_commandlist'])) { |
356 | if (empty($GLOBALS['_PEAR_Command_commandlist'])) { |
357 | PEAR_Command::registerCommands(); |
357 | PEAR_Command::registerCommands(); |
358 | }
|
358 | }
|
359 | if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) { |
359 | if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) { |
360 | $command = $GLOBALS['_PEAR_Command_shortcuts'][$command]; |
360 | $command = $GLOBALS['_PEAR_Command_shortcuts'][$command]; |
361 | }
|
361 | }
|
362 | if (!isset($GLOBALS['_PEAR_Command_commandlist'][$command])) { |
362 | if (!isset($GLOBALS['_PEAR_Command_commandlist'][$command])) { |
363 | return null; |
363 | return null; |
364 | }
|
364 | }
|
365 | $obj = &PEAR_Command::getObject($command); |
365 | $obj = &PEAR_Command::getObject($command); |
366 | return $obj->getGetoptArgs($command, $short_args, $long_args); |
366 | return $obj->getGetoptArgs($command, $short_args, $long_args); |
367 | }
|
367 | }
|
368 | 368 | ||
369 | // }}}
|
369 | // }}}
|
370 | // {{{ getDescription()
|
370 | // {{{ getDescription()
|
371 | 371 | ||
372 | /**
|
372 | /**
|
373 | * Get description for a command.
|
373 | * Get description for a command.
|
374 | *
|
374 | *
|
375 | * @param string $command Name of the command
|
375 | * @param string $command Name of the command
|
376 | *
|
376 | *
|
377 | * @return string command description
|
377 | * @return string command description
|
378 | *
|
378 | *
|
379 | * @access public
|
379 | * @access public
|
380 | * @static
|
380 | * @static
|
381 | */
|
381 | */
|
382 | function getDescription($command) |
382 | function getDescription($command) |
383 | {
|
383 | {
|
384 | if (!isset($GLOBALS['_PEAR_Command_commanddesc'][$command])) { |
384 | if (!isset($GLOBALS['_PEAR_Command_commanddesc'][$command])) { |
385 | return null; |
385 | return null; |
386 | }
|
386 | }
|
387 | return $GLOBALS['_PEAR_Command_commanddesc'][$command]; |
387 | return $GLOBALS['_PEAR_Command_commanddesc'][$command]; |
388 | }
|
388 | }
|
389 | 389 | ||
390 | // }}}
|
390 | // }}}
|
391 | // {{{ getHelp()
|
391 | // {{{ getHelp()
|
392 | 392 | ||
393 | /**
|
393 | /**
|
394 | * Get help for command.
|
394 | * Get help for command.
|
395 | *
|
395 | *
|
396 | * @param string $command Name of the command to return help for
|
396 | * @param string $command Name of the command to return help for
|
397 | *
|
397 | *
|
398 | * @access public
|
398 | * @access public
|
399 | * @static
|
399 | * @static
|
400 | */
|
400 | */
|
401 | function getHelp($command) |
401 | function getHelp($command) |
402 | {
|
402 | {
|
403 | $cmds = PEAR_Command::getCommands(); |
403 | $cmds = PEAR_Command::getCommands(); |
404 | if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) { |
404 | if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) { |
405 | $command = $GLOBALS['_PEAR_Command_shortcuts'][$command]; |
405 | $command = $GLOBALS['_PEAR_Command_shortcuts'][$command]; |
406 | }
|
406 | }
|
407 | if (isset($cmds[$command])) { |
407 | if (isset($cmds[$command])) { |
408 | $obj = &PEAR_Command::getObject($command); |
408 | $obj = &PEAR_Command::getObject($command); |
409 | return $obj->getHelp($command); |
409 | return $obj->getHelp($command); |
410 | }
|
410 | }
|
411 | return false; |
411 | return false; |
412 | }
|
412 | }
|
413 | // }}}
|
413 | // }}}
|
414 | }
|
414 | }
|
415 | 415 | ||
416 | ?>
|
416 | ?>
|
417 | 417 |