Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit fb1ebfd

Browse files
committed
Added missing system check if command exists
1 parent a269a69 commit fb1ebfd

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/System/System.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ public abstract function getCurrentUser();
4040
/** @return string */
4141
public abstract function getCurrentUserHome();
4242

43-
/** @return string */
43+
/**
44+
* @param string $cmdName
45+
* @return boolean
46+
*/
47+
public abstract function checkIfCommandExists($cmdName);
48+
49+
/** @return string */
4450
public abstract function getAppDataDirectory();
4551

4652
/**

src/System/UnixSystem.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ public function getCurrentUserHome()
3232
}
3333
}
3434

35+
/**
36+
* @param string $cmdName
37+
* @return boolean
38+
*/
39+
public function checkIfCommandExists($cmdName)
40+
{
41+
if (!function_exists('exec')) {
42+
return false;
43+
}
44+
45+
$sysResponse = exec(
46+
'PATH='.getenv('PATH').'; '.
47+
"if command -v ".$cmdName." >/dev/null 2>&1; then echo \"true\"; else echo \"false\"; fi;"
48+
);
49+
50+
return filter_var($sysResponse, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
51+
}
52+
3553
/**
3654
* Returns true if the path is a "valid" path and is writable (even if the complete path does not yet exist).
3755
* @param string $path

0 commit comments

Comments
 (0)