Conditions | 5 |
Paths | 5 |
Total Lines | 21 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
26 | public static function hasBinary($binaryName) { |
||
27 | $exec = Exec::create(); |
||
28 | if (self::isWindows()) { |
||
29 | // 'where.exe' uses 0 for success, 1 for failure to find |
||
30 | $exec->run('where.exe', '/q', $binaryName); |
||
31 | return $exec->getStatus() === 0; |
||
32 | } |
||
33 | // 'which' uses 0 for success, 1 for failure to find |
||
34 | $exec->run('which', $binaryName); |
||
35 | if ($exec->getStatus() === 0) { |
||
36 | return true; |
||
37 | } |
||
38 | // 'whereis' does not use status codes. Check for a matching line instead. |
||
39 | $exec->run('whereis', '-b', $binaryName); |
||
40 | foreach ($exec->getOutput() as $line) { |
||
41 | if (preg_match('/^' . preg_quote($binaryName) . ': .*$/', $line) === 1) { |
||
42 | return true; |
||
43 | } |
||
44 | } |
||
45 | return false; |
||
46 | } |
||
47 | } |
||
48 |