@@ -107,6 +107,7 @@ class PEAR_Command
107
107
* @return object the command object or a PEAR error
108
108
*
109
109
* @access public
110
+ * @static
110
111
*/
111
112
function factory ($ command , &$ config )
112
113
{
@@ -116,11 +117,14 @@ function factory($command, &$config)
116
117
if (isset ($ GLOBALS ['_PEAR_Command_shortcuts ' ][$ command ])) {
117
118
$ command = $ GLOBALS ['_PEAR_Command_shortcuts ' ][$ command ];
118
119
}
119
- $ class = @$ GLOBALS ['_PEAR_Command_commandlist ' ][$ command ];
120
- if (empty ($ class )) {
120
+ if (!isset ($ GLOBALS ['_PEAR_Command_commandlist ' ][$ command ])) {
121
121
return PEAR ::raiseError ("unknown command ` $ command' " );
122
122
}
123
- $ ui = PEAR_Command::getFrontendObject ();
123
+ $ class = $ GLOBALS ['_PEAR_Command_commandlist ' ][$ command ];
124
+ if (!class_exists ($ class )) {
125
+ return PEAR ::raiseError ("unknown command ` $ command' " );
126
+ }
127
+ $ ui =& PEAR_Command::getFrontendObject ();
124
128
$ obj = &new $ class ($ ui , $ config );
125
129
return $ obj ;
126
130
}
@@ -132,6 +136,7 @@ function factory($command, &$config)
132
136
* Get instance of frontend object.
133
137
*
134
138
* @return object
139
+ * @static
135
140
*/
136
141
function &getFrontendObject ()
137
142
{
@@ -150,16 +155,21 @@ function &getFrontendObject()
150
155
* @param string $uiclass Name of class implementing the frontend
151
156
*
152
157
* @return object the frontend object, or a PEAR error
158
+ * @static
153
159
*/
154
160
function &setFrontendClass ($ uiclass )
155
161
{
156
162
if (is_object ($ GLOBALS ['_PEAR_Command_uiobject ' ]) &&
157
163
strtolower ($ uiclass ) == get_class ($ GLOBALS ['_PEAR_Command_uiobject ' ])) {
158
- return ;
164
+ return $ GLOBALS [ ' _PEAR_Command_uiobject ' ] ;
159
165
}
160
- $ file = str_replace ('_ ' , '/ ' , $ uiclass ) . '.php ' ;
161
- @include_once $ file ;
162
- if (class_exists (strtolower ($ uiclass ))) {
166
+ if (!class_exists ($ uiclass )) {
167
+ $ file = str_replace ('_ ' , '/ ' , $ uiclass ) . '.php ' ;
168
+ if (PEAR_Command::isIncludeable ($ file )) {
169
+ include_once $ file ;
170
+ }
171
+ }
172
+ if (class_exists ($ uiclass )) {
163
173
$ obj = &new $ uiclass ;
164
174
// quick test to see if this class implements a few of the most
165
175
// important frontend methods
@@ -168,21 +178,47 @@ function &setFrontendClass($uiclass)
168
178
$ GLOBALS ['_PEAR_Command_uiclass ' ] = $ uiclass ;
169
179
return $ obj ;
170
180
} else {
171
- return PEAR ::raiseError ("not a frontend class: $ uiclass " );
181
+ $ err = PEAR ::raiseError ("not a frontend class: $ uiclass " );
182
+ return $ err ;
172
183
}
173
184
}
174
- return PEAR ::raiseError ("no such class: $ uiclass " );
185
+ $ err = PEAR ::raiseError ("no such class: $ uiclass " );
186
+ return $ err ;
175
187
}
176
188
177
189
// }}}
178
190
// {{{ setFrontendType()
179
191
192
+ // }}}
193
+ // {{{ isIncludeable()
194
+
195
+ /**
196
+ * @param string $path relative or absolute include path
197
+ * @return boolean
198
+ * @static
199
+ */
200
+ function isIncludeable ($ path )
201
+ {
202
+ if (file_exists ($ path ) && is_readable ($ path )) {
203
+ return true ;
204
+ }
205
+ $ ipath = explode (PATH_SEPARATOR , ini_get ('include_path ' ));
206
+ foreach ($ ipath as $ include ) {
207
+ $ test = realpath ($ include . DIRECTORY_SEPARATOR . $ path );
208
+ if (file_exists ($ test ) && is_readable ($ test )) {
209
+ return true ;
210
+ }
211
+ }
212
+ return false ;
213
+ }
214
+
180
215
/**
181
216
* Set current frontend.
182
217
*
183
218
* @param string $uitype Name of the frontend type (for example "CLI")
184
219
*
185
220
* @return object the frontend object, or a PEAR error
221
+ * @static
186
222
*/
187
223
function setFrontendType ($ uitype )
188
224
{
@@ -209,6 +245,7 @@ function setFrontendType($uitype)
209
245
* @return bool TRUE on success, a PEAR error on failure
210
246
*
211
247
* @access public
248
+ * @static
212
249
*/
213
250
function registerCommands ($ merge = false , $ dir = null )
214
251
{
@@ -256,6 +293,7 @@ function registerCommands($merge = false, $dir = null)
256
293
* @return array command => implementing class
257
294
*
258
295
* @access public
296
+ * @static
259
297
*/
260
298
function getCommands ()
261
299
{
@@ -274,6 +312,7 @@ function getCommands()
274
312
* @return array shortcut => command
275
313
*
276
314
* @access public
315
+ * @static
277
316
*/
278
317
function getShortcuts ()
279
318
{
@@ -296,16 +335,17 @@ function getShortcuts()
296
335
* @return void
297
336
*
298
337
* @access public
338
+ * @static
299
339
*/
300
340
function getGetoptArgs ($ command , &$ short_args , &$ long_args )
301
341
{
302
342
if (empty ($ GLOBALS ['_PEAR_Command_commandlist ' ])) {
303
343
PEAR_Command::registerCommands ();
304
344
}
305
- $ class = @$ GLOBALS ['_PEAR_Command_commandlist ' ][$ command ];
306
- if (empty ($ class )) {
345
+ if (!isset ($ GLOBALS ['_PEAR_Command_commandlist ' ][$ command ])) {
307
346
return null ;
308
347
}
348
+ $ class = $ GLOBALS ['_PEAR_Command_commandlist ' ][$ command ];
309
349
$ obj = &$ GLOBALS ['_PEAR_Command_objects ' ][$ class ];
310
350
return $ obj ->getGetoptArgs ($ command , $ short_args , $ long_args );
311
351
}
@@ -321,10 +361,14 @@ function getGetoptArgs($command, &$short_args, &$long_args)
321
361
* @return string command description
322
362
*
323
363
* @access public
364
+ * @static
324
365
*/
325
366
function getDescription ($ command )
326
367
{
327
- return @$ GLOBALS ['_PEAR_Command_commanddesc ' ][$ command ];
368
+ if (!isset ($ GLOBALS ['_PEAR_Command_commanddesc ' ][$ command ])) {
369
+ return null ;
370
+ }
371
+ return $ GLOBALS ['_PEAR_Command_commanddesc ' ][$ command ];
328
372
}
329
373
330
374
// }}}
@@ -336,6 +380,7 @@ function getDescription($command)
336
380
* @param string $command Name of the command to return help for
337
381
*
338
382
* @access public
383
+ * @static
339
384
*/
340
385
function getHelp ($ command )
341
386
{
0 commit comments