mirror of
https://github.com/php/php-src.git
synced 2026-04-27 10:16:41 +02:00
added 'System::type()' (show the full path of a command)
Copied almost verbatim from Stig's PEAR_Dependency::checkProgram()
This commit is contained in:
+26
-1
@@ -315,7 +315,6 @@ class System extends PEAR
|
||||
$tmpdir = $opt[1];
|
||||
}
|
||||
}
|
||||
//print_r($opts);
|
||||
$prefix = (isset($opts[1][0])) ? $opts[1][0] : 'tmp';
|
||||
if (!isset($tmpdir)) {
|
||||
$tmpdir = System::tmpdir();
|
||||
@@ -350,5 +349,31 @@ class System extends PEAR
|
||||
}
|
||||
return '/tmp';
|
||||
}
|
||||
|
||||
/**
|
||||
* The "type" command (show the full path of a command)
|
||||
*
|
||||
* @param string $program The command to search for
|
||||
* @return mixed A string with the full path or false if not found
|
||||
* @author Stig Bakken <ssb@fast.no>
|
||||
*/
|
||||
function type($program)
|
||||
{
|
||||
// full path given
|
||||
if (basename($program) != $program) {
|
||||
return (@is_executable($program)) ? $program : false;
|
||||
}
|
||||
// XXX FIXME honor safe mode
|
||||
$path_delim = OS_WINDOWS ? ';' : ':';
|
||||
$exe_suffix = OS_WINDOWS ? '.exe' : '';
|
||||
$path_elements = explode($path_delim, getenv('PATH'));
|
||||
foreach ($path_elements as $dir) {
|
||||
$file = $dir . DIRECTORY_SEPARATOR . $program . $exe_suffix;
|
||||
if (@is_file($file) && @is_executable($file)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user