1 | <?php |
||
5 | class OperatingSystemDetector |
||
6 | { |
||
7 | const MAC = 1; |
||
8 | const LINUX = 2; |
||
9 | const WINDOWS = 3; |
||
10 | |||
11 | private $os; |
||
12 | private $distro; |
||
13 | |||
14 | public function __construct() |
||
15 | { |
||
16 | $this->os = strtolower(php_uname('s')); |
||
17 | |||
18 | if ($this->isLinux()) { |
||
19 | $this->distro = $this->getLinuxDistro(); |
||
20 | } |
||
21 | } |
||
22 | |||
23 | public function getOperatingSystem() |
||
24 | { |
||
25 | return $this->os; |
||
26 | } |
||
27 | |||
28 | public function getLinuxDistribution() |
||
29 | { |
||
30 | return $this->distro; |
||
31 | } |
||
32 | |||
33 | public function isMac() |
||
34 | { |
||
35 | return $this->os === 'darwin'; |
||
36 | } |
||
37 | |||
38 | public function isLinux() |
||
39 | { |
||
40 | return $this->os === 'linux'; |
||
41 | } |
||
42 | |||
43 | public function isDebian() |
||
44 | { |
||
45 | return $this->isLinux() && in_array($this->distro, [ |
||
46 | 'debian', |
||
47 | 'ubuntu', |
||
48 | 'linuxmint', |
||
49 | 'elementary os', |
||
50 | 'kali', |
||
51 | ]); |
||
52 | } |
||
53 | |||
54 | public function isRedHat() |
||
63 | |||
64 | /** |
||
65 | * @return string |
||
66 | */ |
||
67 | private function getLinuxDistro() |
||
86 | } |
||
87 |