-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOsTool.php
82 lines (69 loc) · 1.74 KB
/
OsTool.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace Ling\Bat;
/**
* The OsTool class.
*/
class OsTool
{
/**
* Returns whether or not the program exists on the machine.
*
* @param string $program , the absolute path to the program
* @return bool
* @throws \Exception
*/
public static function hasProgram(string $program)
{
if (true === self::isUnix()) {
ob_start();
passthru("which $program");
return (strlen(ob_get_clean()) > 0);
} else {
// todo: implement for windows...
throw new \Exception("Sorry dude, not implemented now for windows machine, please improve this class");
}
}
/**
* Returns whether the current machine is running on Windows OS.
*
* @return bool
*/
public static function isWindows()
{
return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
}
/**
* Returns whether the current machine is running on Mac OS.
*
* @return bool
*/
public static function isMac()
{
return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN');
}
/**
* Returns whether the current machine is running on a Unix OS.
*
* @return bool
*/
public static function isUnix()
{
/**
* If it's not windows, it's unix, isn't it?
*/
return (false === self::isWindows());
}
/**
* Clears the console screen.
*/
public static function clear()
{
if (true === self::isWindows()) {
// https://stackoverflow.com/questions/24327544/how-can-clear-screen-in-php-cli-like-cls-command
// didn't test personally
system('cls');
} else {
system('clear');
}
}
}