Skip to content

Commit e57b75e

Browse files
author
Greg Beaver
committed
fix Bug #324 pear -G gives Fatal Error (PHP-GTK not installed, but error is at engine level)
1 parent c31d958 commit e57b75e

File tree

2 files changed

+58
-12
lines changed

2 files changed

+58
-12
lines changed

pear/PEAR/Command.php

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class PEAR_Command
107107
* @return object the command object or a PEAR error
108108
*
109109
* @access public
110+
* @static
110111
*/
111112
function factory($command, &$config)
112113
{
@@ -116,11 +117,14 @@ function factory($command, &$config)
116117
if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) {
117118
$command = $GLOBALS['_PEAR_Command_shortcuts'][$command];
118119
}
119-
$class = @$GLOBALS['_PEAR_Command_commandlist'][$command];
120-
if (empty($class)) {
120+
if (!isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
121121
return PEAR::raiseError("unknown command `$command'");
122122
}
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();
124128
$obj = &new $class($ui, $config);
125129
return $obj;
126130
}
@@ -132,6 +136,7 @@ function factory($command, &$config)
132136
* Get instance of frontend object.
133137
*
134138
* @return object
139+
* @static
135140
*/
136141
function &getFrontendObject()
137142
{
@@ -150,16 +155,21 @@ function &getFrontendObject()
150155
* @param string $uiclass Name of class implementing the frontend
151156
*
152157
* @return object the frontend object, or a PEAR error
158+
* @static
153159
*/
154160
function &setFrontendClass($uiclass)
155161
{
156162
if (is_object($GLOBALS['_PEAR_Command_uiobject']) &&
157163
strtolower($uiclass) == get_class($GLOBALS['_PEAR_Command_uiobject'])) {
158-
return;
164+
return $GLOBALS['_PEAR_Command_uiobject'];
159165
}
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)) {
163173
$obj = &new $uiclass;
164174
// quick test to see if this class implements a few of the most
165175
// important frontend methods
@@ -168,21 +178,47 @@ function &setFrontendClass($uiclass)
168178
$GLOBALS['_PEAR_Command_uiclass'] = $uiclass;
169179
return $obj;
170180
} else {
171-
return PEAR::raiseError("not a frontend class: $uiclass");
181+
$err = PEAR::raiseError("not a frontend class: $uiclass");
182+
return $err;
172183
}
173184
}
174-
return PEAR::raiseError("no such class: $uiclass");
185+
$err = PEAR::raiseError("no such class: $uiclass");
186+
return $err;
175187
}
176188

177189
// }}}
178190
// {{{ setFrontendType()
179191

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+
180215
/**
181216
* Set current frontend.
182217
*
183218
* @param string $uitype Name of the frontend type (for example "CLI")
184219
*
185220
* @return object the frontend object, or a PEAR error
221+
* @static
186222
*/
187223
function setFrontendType($uitype)
188224
{
@@ -209,6 +245,7 @@ function setFrontendType($uitype)
209245
* @return bool TRUE on success, a PEAR error on failure
210246
*
211247
* @access public
248+
* @static
212249
*/
213250
function registerCommands($merge = false, $dir = null)
214251
{
@@ -256,6 +293,7 @@ function registerCommands($merge = false, $dir = null)
256293
* @return array command => implementing class
257294
*
258295
* @access public
296+
* @static
259297
*/
260298
function getCommands()
261299
{
@@ -274,6 +312,7 @@ function getCommands()
274312
* @return array shortcut => command
275313
*
276314
* @access public
315+
* @static
277316
*/
278317
function getShortcuts()
279318
{
@@ -296,16 +335,17 @@ function getShortcuts()
296335
* @return void
297336
*
298337
* @access public
338+
* @static
299339
*/
300340
function getGetoptArgs($command, &$short_args, &$long_args)
301341
{
302342
if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
303343
PEAR_Command::registerCommands();
304344
}
305-
$class = @$GLOBALS['_PEAR_Command_commandlist'][$command];
306-
if (empty($class)) {
345+
if (!isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
307346
return null;
308347
}
348+
$class = $GLOBALS['_PEAR_Command_commandlist'][$command];
309349
$obj = &$GLOBALS['_PEAR_Command_objects'][$class];
310350
return $obj->getGetoptArgs($command, $short_args, $long_args);
311351
}
@@ -321,10 +361,14 @@ function getGetoptArgs($command, &$short_args, &$long_args)
321361
* @return string command description
322362
*
323363
* @access public
364+
* @static
324365
*/
325366
function getDescription($command)
326367
{
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];
328372
}
329373

330374
// }}}
@@ -336,6 +380,7 @@ function getDescription($command)
336380
* @param string $command Name of the command to return help for
337381
*
338382
* @access public
383+
* @static
339384
*/
340385
function getHelp($command)
341386
{

pear/package-PEAR.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ PEAR Installer:
5757
* Bug #249 installing from an url doesnt work
5858
* Bug #248 --force command does not work as expected
5959
* Bug #293 [Patch] PEAR_Error not calling static method callbacks for error-handler
60+
* Bug #324 pear -G gives Fatal Error (PHP-GTK not installed, but error is at engine level)
6061

6162
</notes>
6263
<provides type="class" name="OS_Guess" />

0 commit comments

Comments
 (0)