浏览代码

[Process] workaround a faulty implementation of is_executable on Windows

Johannes M. Schmitt 13 年之前
父节点
当前提交
9fb15c7cb2
共有 1 个文件被更改,包括 10 次插入1 次删除
  1. 10 1
      src/Symfony/Component/Process/ExecutableFinder.php

+ 10 - 1
src/Symfony/Component/Process/ExecutableFinder.php

@@ -19,8 +19,17 @@ namespace Symfony\Component\Process;
  */
 class ExecutableFinder
 {
+    private static $isWindows;
+
     private $suffixes = array('.exe', '.bat', '.cmd', '.com');
 
+    public function __construct()
+    {
+        if (null === self::$isWindows) {
+            self::$isWindows = 0 === stripos(PHP_OS, 'win');
+        }
+    }
+
     public function setSuffixes(array $suffixes)
     {
         $this->suffixes = $suffixes;
@@ -61,7 +70,7 @@ class ExecutableFinder
         $suffixes = DIRECTORY_SEPARATOR == '\\' ? (getenv('PATHEXT') ? explode(PATH_SEPARATOR, getenv('PATHEXT')) : $this->suffixes) : array('');
         foreach ($suffixes as $suffix) {
             foreach ($dirs as $dir) {
-                if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && is_executable($file)) {
+                if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && (self::$isWindows || is_executable($file))) {
                     return $file;
                 }
             }