From: Tomas V.V.Cox Date: Wed, 6 Feb 2002 08:32:00 +0000 (+0000) Subject: added 'System::type()' (show the full path of a command) X-Git-Tag: php-4.2.0RC1~410 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b91c0777106942a7536758fcc8026ee97f4866f6;p=php added 'System::type()' (show the full path of a command) Copied almost verbatim from Stig's PEAR_Dependency::checkProgram() --- 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 + */ + 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