Skip to content

Commit 5e3b12a

Browse files
committed
add systemCommandExists
1 parent 3a59ed1 commit 5e3b12a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/Ubiquity/devtools/utils/FileUtils.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ public static function writeFile($filename,$data){
2222
}
2323

2424
public static function xcopy($source, $dest, $permissions = 0755){
25-
$path = pathinfo($dest);
26-
if (!file_exists($path['dirname'])) {
27-
mkdir($path['dirname'], 0777, true);
28-
}
25+
$path = pathinfo($dest);
26+
if (!file_exists($path['dirname'])) {
27+
mkdir($path['dirname'], 0777, true);
28+
}
2929
if (is_link($source)) {
3030
return symlink(readlink($source), $dest);
3131
}
@@ -69,4 +69,16 @@ public static function cleanPathname($path){
6969
}
7070
return \realpath($path);
7171
}
72+
73+
public static function systemCommandExists($command) :bool {
74+
$windows = \strpos(PHP_OS, 'WIN') === 0;
75+
$test = $windows ? 'where' : 'command -v';
76+
$commands=explode("\n",\trim(\shell_exec("$test $command")));
77+
foreach ($commands as $cmd){
78+
if($cmd!=null && \file_exists($cmd)){
79+
return true;
80+
}
81+
}
82+
return false;
83+
}
7284
}

0 commit comments

Comments
 (0)