Skip to content

Commit d488478

Browse files
Merge remote-tracking branch 'origin/master'
2 parents 9171280 + b4dd843 commit d488478

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/Util/Cli.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static function detectCmdLocation($cmd, $path = null, $optionalLocations
8484
}
8585

8686
// checking environment variable.
87-
$pathList = explode(PATH_SEPARATOR, $_SERVER['PATH']);
87+
$pathList = explode(PATH_SEPARATOR, self::getEnvPath());
8888
foreach ($pathList as $path) {
8989
$command = $path . DIRECTORY_SEPARATOR . $cmd;
9090
$bin = self::isExecutable($command);
@@ -104,6 +104,23 @@ public static function detectCmdLocation($cmd, $path = null, $optionalLocations
104104
throw new RuntimeException(sprintf('\'%s\' was nowhere to be found please specify the correct path', $cmd));
105105
}
106106

107+
/**
108+
* Return local $PATH variable.
109+
*
110+
* @return string
111+
* @throws \RuntimeException
112+
*/
113+
public static function getEnvPath()
114+
{
115+
// check for unix and windows case $_SERVER index
116+
foreach (array('PATH', 'Path', 'path') as $index) {
117+
if (isset($_SERVER[$index])) {
118+
return $_SERVER[$index];
119+
}
120+
}
121+
throw new RuntimeException('cant find local PATH variable');
122+
}
123+
107124
/**
108125
* Returns the executable command if the command is executable, null otherwise.
109126
* Search for $command.exe on Windows systems.

0 commit comments

Comments
 (0)