File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed
Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1010use Leaf \Sprout \Process \Npm ;
1111use Leaf \Sprout \Style ;
1212use Leaf \Sprout \Prompt ;
13+ use Leaf \Sprout \System ;
1314
1415/**
1516 * Leaf Sprout
@@ -53,6 +54,14 @@ public function prompt(array $prompt)
5354 return (new Prompt ($ prompt ))->ask ();
5455 }
5556
57+ /**
58+ * Return an instance of system utils
59+ */
60+ public function system (): System
61+ {
62+ return new System ();
63+ }
64+
5665 /**
5766 * Prompt a confirmation
5867 * @param string $message The confirmation message
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Leaf \Sprout ;
4+
5+ /**
6+ * Lightweight system utilities
7+ * ---
8+ * System related helper functions for your sprout applications
9+ */
10+ class System
11+ {
12+ /**
13+ * Check if the current OS is Windows
14+ */
15+ public static function isWindows (): bool
16+ {
17+ return strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' ;
18+ }
19+
20+ /**
21+ * Check if the current OS is Linux
22+ */
23+ public static function isLinux (): bool
24+ {
25+ return PHP_OS === 'Linux ' ;
26+ }
27+
28+ /**
29+ * Check if the current OS is MacOS
30+ */
31+ public static function isMacOS (): bool
32+ {
33+ return PHP_OS === 'Darwin ' ;
34+ }
35+
36+ /**
37+ * Check if a system command exists
38+ * @return bool
39+ */
40+ public static function commandExists (string $ cmd )
41+ {
42+ if (static ::isWindows ()) {
43+ return !empty (shell_exec (sprintf ('where %s 2>NUL ' , escapeshellarg ($ cmd ))));
44+ }
45+
46+ return !empty (shell_exec (sprintf ('command -v %s 2>/dev/null ' , escapeshellarg ($ cmd ))));
47+ }
48+ }
You can’t perform that action at this time.
0 commit comments