| 1 |
<?php |
| 2 |
namespace ExecWithFallback; |
| 3 |
|
| 4 |
/** |
| 5 |
* Check if any of the methods are available on the system. |
| 6 |
* |
| 7 |
* @package ExecWithFallback |
| 8 |
* @author Bjørn Rosell <[email protected]> |
| 9 |
*/ |
| 10 |
class Availability extends ExecWithFallback |
| 11 |
{ |
| 12 |
|
| 13 |
/** |
| 14 |
* Check if any of the methods are available on the system. |
| 15 |
* |
| 16 |
* @param boolean $needResultCode Whether the code using this library is going to supply $result_code to the exec |
| 17 |
* call. This matters because shell_exec is only available when not. |
| 18 |
*/ |
| 19 |
public static function anyAvailable($needResultCode = true) |
| 20 |
{ |
| 21 |
foreach (self::$methods as $method) { |
| 22 |
if (self::methodAvailable($method, $needResultCode)) { |
| 23 |
return true; |
| 24 |
} |
| 25 |
} |
| 26 |
return false; |
| 27 |
} |
| 28 |
|
| 29 |
public static function methodAvailable($method, $needResultCode = true) |
| 30 |
{ |
| 31 |
if (!ExecWithFallback::functionEnabled($method)) { |
| 32 |
return false; |
| 33 |
} |
| 34 |
if ($needResultCode) { |
| 35 |
return ($method != 'shell_exec'); |
| 36 |
} |
| 37 |
return true; |
| 38 |
} |
| 39 |
} |
| 40 |
|