]> granicus.if.org Git - php/commitdiff
added 'System::type()' (show the full path of a command)
authorTomas V.V.Cox <cox@php.net>
Wed, 6 Feb 2002 08:32:00 +0000 (08:32 +0000)
committerTomas V.V.Cox <cox@php.net>
Wed, 6 Feb 2002 08:32:00 +0000 (08:32 +0000)
Copied almost verbatim from Stig's PEAR_Dependency::checkProgram()

pear/System.php

index fd90901295fee5664624210f096d7598b2bece0c..df47689d3ffe4e88c5240bde5dd53b232c84e0a3 100644 (file)
@@ -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