1 | <?php |
||
15 | class OperatingSystem |
||
16 | { |
||
17 | /** |
||
18 | * @var int |
||
19 | */ |
||
20 | const UID_ROOT = 0; |
||
21 | |||
22 | /** |
||
23 | * Returns true if operating system is |
||
24 | * based on GNU linux. |
||
25 | * |
||
26 | * @return boolean |
||
27 | */ |
||
28 | public static function isLinux() |
||
32 | |||
33 | /** |
||
34 | * Returns true if operating system is |
||
35 | * based on Microsoft Windows. |
||
36 | * |
||
37 | * @return boolean |
||
38 | */ |
||
39 | public static function isWindows() |
||
43 | |||
44 | /** |
||
45 | * Returns true if operating system is |
||
46 | * based on novell netware. |
||
47 | * |
||
48 | * @return boolean |
||
49 | */ |
||
50 | public static function isNetware() |
||
54 | |||
55 | /** |
||
56 | * Returns true if operating system is |
||
57 | * based on apple MacOS. |
||
58 | * |
||
59 | * @return boolean |
||
60 | */ |
||
61 | public static function isMacOs() |
||
65 | |||
66 | /** |
||
67 | * @param string $program |
||
68 | * @return bool |
||
69 | */ |
||
70 | public static function isProgramInstalled($program) |
||
71 | { |
||
72 | if (self::isWindows()) { |
||
73 | return WindowsSystem::isProgramInstalled($program); |
||
74 | } |
||
75 | |||
76 | $out = null; |
||
77 | $return = null; |
||
78 | @exec('which ' . $program, $out, $return); |
||
|
|||
79 | |||
80 | return $return === 0; |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @return string |
||
85 | */ |
||
86 | public static function getHomeDir() |
||
87 | { |
||
88 | if (self::isWindows()) { |
||
89 | return getenv('USERPROFILE'); |
||
90 | } |
||
91 | |||
92 | return getenv('HOME'); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Test for Root UID on a POSIX system if posix_getuid() is available. |
||
97 | * |
||
98 | * Returns false negatives if posix_getuid() is not available. |
||
99 | * |
||
100 | * @return bool |
||
101 | */ |
||
102 | public static function isRoot() |
||
106 | |||
107 | /** |
||
108 | * get current working directory |
||
109 | * |
||
110 | * @return string the current working directory on success, or false on failure. |
||
111 | */ |
||
112 | public static function getCwd() |
||
116 | |||
117 | /** |
||
118 | * Retrieve path to php binary |
||
119 | * |
||
120 | * @return string |
||
121 | */ |
||
122 | public static function getPhpBinary() |
||
133 | } |
||
134 |
If you suppress an error, we recommend checking for the error condition explicitly: