Conditions | 2 |
Paths | 2 |
Total Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
35 | function locateLocalBinaryPath($name) |
||
|
|||
36 | { |
||
37 | $nameEscaped = escapeshellarg($name); |
||
38 | // Try `command`, should cover all Bourne-like shells |
||
39 | // Try `which`, should cover most other cases |
||
40 | // Fallback to `type` command, if the rest fails |
||
41 | $path = runLocally("command -v $nameEscaped || which $nameEscaped || type -p $nameEscaped"); |
||
42 | if ($path) { |
||
43 | // Deal with issue when `type -p` outputs something like `type -ap` in some implementations |
||
44 | return trim(str_replace("$name is", "", $path)); |
||
45 | } |
||
46 | throw new \RuntimeException("Can't locate [$nameEscaped] on instance '" . get('default_stage') . "' - neither of [command|which|type] commands are available"); |
||
47 | } |
||
48 | } |
||
49 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.