summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas V.V.Cox <cox@php.net>2002-02-06 08:32:00 +0000
committerTomas V.V.Cox <cox@php.net>2002-02-06 08:32:00 +0000
commitb91c0777106942a7536758fcc8026ee97f4866f6 (patch)
tree50326ed99f2660484f8f307d314680ec4710ab4f
parent39ad45326656ea54cfd356bb91de7ff71e332aea (diff)
downloadphp-git-b91c0777106942a7536758fcc8026ee97f4866f6.tar.gz
added 'System::type()' (show the full path of a command)
Copied almost verbatim from Stig's PEAR_Dependency::checkProgram()
-rw-r--r--pear/System.php27
1 files changed, 26 insertions, 1 deletions
diff --git a/pear/System.php b/pear/System.php
index fd90901295..df47689d3f 100644
--- a/pear/System.php
+++ b/pear/System.php
@@ -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;
+ }
}
?> \ No newline at end of file