1 | <?php |
||
2 | /* |
||
3 | * This file is part of the "andrey-helldar/support" project. |
||
4 | * |
||
5 | * For the full copyright and license information, please view the LICENSE |
||
6 | * file that was distributed with this source code. |
||
7 | * |
||
8 | * @author Andrey Helldar <[email protected]> |
||
9 | * |
||
10 | * @copyright 2021 Andrey Helldar |
||
11 | * |
||
12 | * @license MIT |
||
13 | * |
||
14 | * @see https://github.com/andrey-helldar/support |
||
15 | */ |
||
16 | |||
17 | namespace Helldar\Support\Helpers; |
||
18 | |||
19 | use Helldar\Support\Facades\Helpers\Str as StrHelper; |
||
20 | |||
21 | /** |
||
22 | * @see https://www.php.net/manual/ru/reserved.constants.php |
||
23 | */ |
||
24 | class OS |
||
25 | { |
||
26 | 2 | public function isUnix(): bool |
|
27 | { |
||
28 | 2 | return ! $this->isWindows() && ! $this->isUnknown(); |
|
29 | } |
||
30 | |||
31 | 4 | public function isWindows(): bool |
|
32 | { |
||
33 | 4 | return $this->family() === 'windows'; |
|
34 | } |
||
35 | |||
36 | 2 | public function isBSD(): bool |
|
37 | { |
||
38 | 2 | return $this->family() === 'bsd'; |
|
39 | } |
||
40 | |||
41 | 2 | public function isDarwin(): bool |
|
42 | { |
||
43 | 2 | return $this->family() === 'darwin'; |
|
44 | } |
||
45 | |||
46 | 2 | public function isSolaris(): bool |
|
47 | { |
||
48 | 2 | return $this->family() === 'solaris'; |
|
49 | } |
||
50 | |||
51 | 2 | public function isLinux(): bool |
|
52 | { |
||
53 | 2 | return $this->family() === 'linux'; |
|
54 | } |
||
55 | |||
56 | 4 | public function isUnknown(): bool |
|
57 | { |
||
58 | 4 | return $this->family() === 'unknown'; |
|
59 | } |
||
60 | |||
61 | 16 | public function family(bool $lower = true): string |
|
62 | { |
||
63 | 16 | $family = version_compare(PHP_VERSION, '7.2', '<') ? PHP_OS : PHP_OS_FAMILY; |
|
64 | |||
65 | 16 | return $lower ? StrHelper::lower($family) : $family; |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
66 | } |
||
67 | } |
||
68 |